#ifndef BACKEND

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<time.h>
#include<windows.h>
#include<math.h>
#include<mysql.h>

/*Boolean Value*/
#define TRUE 1
#define FALSE 0

/*Keyboard Key*/
#define ENTER_KEY 13
#define ESC_KEY 27
#define BACKSPACE_KEY 8
#define LEFT_ARROW_KEY 75
#define RIGHT_ARROW_KEY 77
#define UP_ARROW_KEY 72
#define DOWN_ARROW_KEY 80

/*Phases*/
#define PLANNING_PHASE "Planning"
#define DESIGN_PHASE "Design"
#define CODING_PHASE "Coding"
#define COMPILE_PHASE "Compile"
#define TESTING_PHASE "Testing"
#define POSTMORTEM_PHASE "Postmortem"
#define AFTER_DEVELOPMENT_PHASE "After Development"

/*Size Estimating Projected LOC Types*/
#define TYPE_OF_PROJECTEC_LOC_BA "BA" //Base Additions
#define TYPE_OF_PROJECTEC_LOC_NF "NF" //New Functions or Object

/*Size Estimating Type: Plan or Actual*/
#define SET_TYPE_PLAN "Plan"
#define SET_TYPE_ACTUAL "Actual"

/*Project Plan Summary Type: Plan, Actual, or ToDate */
#define PPS_TYPE_PLAN "Plan"
#define PPS_TYPE_ACTUAL "Actual"
#define PPS_TYPE_TO_DATE "ToDate"



/*For Colors */
#define GREEN 10
#define RED 12
#define WHITE 15
#define VIOLET 5
#define YELLOW 14
#define LIGHTBLUE 11
#define BLUE 9
#define PINK 13
#define DIRTYRED 4
#define DIRTYREEN 5
#define DIRTYBLUE 3
#define DARKGREEN 2
#define GREY 8

typedef char string1000[10001];
typedef char string700[701];
typedef char string300[301];
typedef char string250[251];
typedef char string150[151];
typedef char string100[101];
typedef char string50[51];
typedef char string25[26];
typedef char string10[11];
typedef char* string;


/*INSERT MYSQL DECLARATION STUFF HERE*/
/*Database Variables*/
string150 opt_host_name = "127.0.0.1"; /* server host (default=localhost) */
string150 opt_user_name = "******"; /* username (default=login name) */
string150 opt_password = "******"; /* password (default=none) */
int opt_port_num = 3306; /* port number (use built-in value) */
string opt_socket_name = NULL; /* socket name (use built-in value) */
string150 opt_db_name = "psp_tsp_project_manager"; /* database name (default=none) */
static unsigned int opt_flags = 0; /* connection flags (none) */

MYSQL *conn; /* pointer to connection handler */

int MYSQL_DEBUG = FALSE;

/*INSERT STRUCTURE AND STUFF HERE*/


typedef struct User{
    string25 id;
    string50 firstName;
    string50 middleName;
    string50 lastName;
    string50 password;
    string50 emailAddress;
    string25 userCurrentlyUsed;
    string25 userActive;
}User;


typedef struct Project{
    string25 id;
    User user;
    string50 date;
    string50 programNumber;
    string50 program;
    string50 language;
    string50 professor;
    string25 previousProjectID;
    string25 projectActive;
}Project;

typedef struct ProjectLinked{
    Project project;
    struct ProjectLinked *prev;
    struct ProjectLinked *next;
}*ProjectLinkedList;


typedef struct TimeRecordingLog{
    string25 id;
    Project project;
    string50 startDate;
    string50 stopDate;
    SYSTEMTIME startTime;
    SYSTEMTIME stopTime;
    float interruptonTime;
    float deltaTime;
    string50 phase;
    string1000 comment;
}TimeRecordingLog;

typedef struct TimeRecordingLogLinked{
    TimeRecordingLog trl;
    struct TimeRecordingLogLinked *prev;
    struct TimeRecordingLogLinked *next;
}*TimeRecordingLogLinkedList;


typedef struct DefectRecordingLog{
    string25 id;
    Project project;
    string50 date;
    string10 number;
    string10 type;
    string50 inject;
    string50 remove;
    float fixTime;
    string10 fixDefect;
    string300 description;
}DefectRecordingLog;

typedef struct DefectRecordingLogLinked{
    DefectRecordingLog drl;
    struct DefectRecordingLogLinked *prev;
    struct DefectRecordingLogLinked *next;
}*DefectRecordingLogLinkedList;

typedef struct TestReportTemplate{
    string25 id;
    Project project;
    string150 testName;
    string150 testObjective;
    string150 testDescription;
    string150 testCondition;
    string150 expectedResult;
    string150 actualResult;
}TestReportTemplate;

typedef struct TestReportTemplateLinked{
    TestReportTemplate trt;
    struct TestReportTemplateLinked *prev;
    struct TestReportTemplateLinked *next;
}*TestReportTemplateLinkedList;


typedef struct ProcessImprovementProposal{
    string25 id;
    Project project;
    string150 pipNumber;
    string150 pipProblemDescription;
    string150 pipProposalDescription;
    string300 pipNotes;
}ProcessImprovementProposal;

typedef struct ProcessImprovementProposalLinked{
    ProcessImprovementProposal pip;
    struct ProcessImprovementProposalLinked *prev;
    struct ProcessImprovementProposalLinked *next;
}*ProcessImprovementProposalLinkedList;


typedef struct TaskPlanningTemplate{
    string25 id;
    Project project;
    string150 taskName;
    float planMinutes;
    float planValue;
    float planCumulativeMinutes;
    float planCumulativeValue;
    string50 planDate;
    string50 actualDate;
    float actualValue;
    float actualCumulativeValue;
    float realActualValue;
    float realActualCumulativeValue;
}TaskPlanningTemplate;


typedef struct TaskPlanningTemplateLinked{
    TaskPlanningTemplate tpt;
    struct TaskPlanningTemplateLinked *prev;
    struct TaskPlanningTemplateLinked *next;
}*TaskPlanningTemplateLinkedList;


typedef struct SchedulePlanningTemplate{
    string25 id;
    Project project;
    string25 dayNumber;
    string50 planDate;
    float planMinutes;
    float planCumulativeMinutes;
    float planCumulativeValue;
    float actualMinutes;
    float actualCumulativeMinutes;
    float actualCumulativeValue;
    float adjustedEarnedValue;
}SchedulePlanningTemplate;


typedef struct SchedulePlanningTemplateLinked{
    SchedulePlanningTemplate spt;
    struct SchedulePlanningTemplateLinked *prev;
    struct SchedulePlanningTemplateLinked *next;
}*SchedulePlanningTemplateLinkedList;


typedef struct SizeEstimatingTemplate{
    string25 id;
    Project project;
    float baseProgamBaseSize;
    float baseProgramLOCDeleted;
    float baseProgramLOCModified;
    float projectedLOC;
    float b0;
    float b1;
    float estimatedNewAndChangedLOC;
    float estimatedTotalLOC;
    float estimatedTotalNewReused;
    float predictionRange;
    float upperPredictionInterval;
    float lowerPredictionInterval;
    float predictionIntervalPercent;
    string50 setType;
}SizeEstimatingTemplate;


typedef struct SizeEstimatingTemplateLinked{
    SizeEstimatingTemplate set;
    struct SizeEstimatingTemplateLinked *prev;
    struct SizeEstimatingTemplateLinked *next;
}*SizeEstimatingTemplateLinkedList;


typedef struct SETProjectedLOC{
    string25 id;
    SizeEstimatingTemplate set;
    string50 setProjectedLOCName;
    string50 setProjectedLOCType;
    string50 setProjectedLOCMethod;
    string50 setProjectedLOCSize;
    float setProjectedLOCLOC;
    string50 typeOfProjectedLOC;
}SETProjectedLOC;


typedef struct SETProjectedLOCLinked{
    SETProjectedLOC setProjectedLOC;
    struct SETProjectedLOCLinked *prev;
    struct SETProjectedLOCLinked *next;
}*SETProjectedLOCLinkedList;


typedef struct SETReusedFunction{
    string25 id;
    SizeEstimatingTemplate set;
    string50 reusedFunctionName;
    float reusedFunctionLOC;
}SETReusedFunction;

typedef struct SETReusedFunctionLinked{
    SETReusedFunction setReusedFunction;
    struct SETReusedFunctionLinked *prev;
    struct SETReusedFunctionLinked *next;
}*SETReusedFunctionLinkedList;


typedef struct ProjectPlanSummary{
    string25 id;
    Project project;
    string25 ppsType;

    float summaryLOCPerHour;
    float summaryPlanTime;
    float summaryActualTime;
    float summaryCPI;
    float summaryPercentReused;
    float summaryPercentNewReused;

    float programSizeBase;
    float programSizeDeleted;
    float programSizeModified;
    float programSizeAdded;
    float programSizeReused;
    float programSizeNewAndChanged;
    float programSizeTotalLOC;
    float programSizeNewReused;

    float trlPlanning;
    float trlDesign;
    float trlCode;
    float trlCompile;
    float trlTest;
    float trlPostmortem;

    float injectPlanning;
    float injectDesign;
    float injectCode;
    float injectCompile;
    float injectTest;


    float removePlanning;
    float removeDesign;
    float removeCode;
    float removeCompile;
    float removeTest;
    float removeAfterDevelopment;

}ProjectPlanSummary;


typedef struct ProjectPlanSummaryLinked{
    ProjectPlanSummary pps;
    struct ProjectPlanSummaryLinked *prev;
    struct ProjectPlanSummaryLinked *next;
}*ProjectPlanSummaryLinkedList;


/*Function Prototypes*/
void convertIntToString(char word[],int number);
int convertStringToInt(char word[]);
float getInterruptionTimeInMinute(time_t start, time_t stop);
TaskPlanningTemplateLinkedList getAllTPTBasedOnProject(TaskPlanningTemplateLinkedList tpt, Project proj);
SchedulePlanningTemplateLinkedList getAllSPTBasedOnProject(SchedulePlanningTemplateLinkedList spt, Project proj);
TaskPlanningTemplateLinkedList getTPTBasedOnPhaseAndProject(TaskPlanningTemplateLinkedList tpt, Project proj,char phase[]);
float getSPTAdjustedEarnedValue(float planCumulativeValue,float actualCumulativeValue);
TimeRecordingLogLinkedList getAllTRLBasedOnStartDateAndProject(TimeRecordingLogLinkedList trl,Project proj,char startDate[]);
SETProjectedLOCLinkedList getAllSETProjectedLOCBasedOnSETAndTypeOfProjectedLOC(SETProjectedLOCLinkedList setProjectedLOC, SizeEstimatingTemplate set, char typeOfProjectedLOC[]);
SETReusedFunctionLinkedList getAllSETReusedFunctionBasedOnSET(SETReusedFunctionLinkedList setReusedFunction, SizeEstimatingTemplate set);
SizeEstimatingTemplateLinkedList getAllSETBasedOnProjectAndType(SizeEstimatingTemplateLinkedList set, Project proj,char setType[]);
TimeRecordingLogLinkedList getAllTRLBasedOnProject(TimeRecordingLogLinkedList trl, Project proj);
DefectRecordingLogLinkedList getAllDRLBasedOnProject(DefectRecordingLogLinkedList drl, Project proj);
Project getProjectByID(char id[]);
ProjectPlanSummaryLinkedList getAllPPSBasedOnProjectAndPPSType(ProjectPlanSummaryLinkedList pps, Project proj,char ppsType[]);



/*System Date and Time Function*/

//get the system month
int getSystemMonth()
{
    time_t now = time(NULL);
    struct tm *t = localtime(&now);
	return t->tm_mon+1;
}


//get the system day
int getSystemDay()
{
	time_t now = time(NULL);
    struct tm *t = localtime(&now);
	return t->tm_mday;
}

//get The System year
int getSystemYear()
{
	time_t now = time(NULL);
    struct tm *t = localtime(&now);
	return t->tm_year+1900;
}

//get the system day of week
int getSystemDayOfWeek()
{
	time_t now = time(NULL);
    struct tm *t = localtime(&now);
	return t->tm_wday;
}

//get the system hour
int getSystemHour()
{
	time_t now = time(NULL);
    struct tm *t = localtime(&now);
	return t->tm_hour;
}

//get the system minute
int getSystemMinute()
{
	time_t now = time(NULL);
    struct tm *t = localtime(&now);
	return t->tm_min;
}

//get the system second
int getSystemSecond()
{
	time_t now = time(NULL);
    struct tm *t = localtime(&now);
	return t->tm_sec;
}

void getSystemDateMySQLFormat(char date[])
{
    string10 month,day,year;
	convertIntToString(month,getSystemMonth());
	convertIntToString(day,getSystemDay());
	convertIntToString(year,getSystemYear());
	strcpy(date,"");
	strcat(date,year);
	strcat(date,"-");
	strcat(date,month);
	strcat(date,"-");
	strcat(date,day);
	date[strlen(date)]='\0';
}

int getHourFromMySQLTimeString(char time[])
{
    string10 hour;
    hour[0] = time[0];
    hour[1] = time[1];
    hour[2] = '\0';
    return convertStringToInt(hour);
}


int getMinuteFromMySQLTimeString(char time[])
{
    string10 minute;
    minute[0] = time[3];
    minute[1] = time[4];
    minute[2] = '\0';
    return convertStringToInt(minute);
}


int getSecondFromMySQLTimeString(char time[])
{
    string10 second;
    second[0] = time[6];
    second[1] = time[7];
    second[2] = '\0';
    return convertStringToInt(second);
}

int getMonthFromMySQLDateString(char date[])
{
    string10 month;
    month[0] = date[5];
    month[1] = date[6];
    month[2] = '\0';
    return convertStringToInt(month);
}


int getDayFromMySQLDateString(char date[])
{
    string10 day;
    day[0] = date[8];
    day[1] = date[9];
    day[2] = '\0';
    return convertStringToInt(day);
}


int getYearFromMySQLDateString(char date[])
{
    string10 year;
    year[0] = date[0];
    year[1] = date[1];
    year[2] = date[2];
    year[3] = date[3];
    year[4] = '\0';
    return convertStringToInt(year);
}






/*Misc Functions*/
void makeFirstLetterCapital(char word[])
{
    if(word[0]>=97&&word[0]<=122)
    {
        word[0]-=32;
    }
}

void encryptPassword(char password[])
{
    int length = strlen(password);
    int i = 0;
    for(i=0;i<length;i++)
    {
        password[i]+=5;
    }
}

void decryptPassword(char password[])
{
    int length = strlen(password);
    int i = 0;
    for(i=0;i<length;i++)
    {
        password[i]-=5;
    }
}

void convertIntToString(char word[],int number)
{
    strcpy(word,"");
	sprintf(word,"%02d",number);
}


void convertFloatToString(char word[],float number)
{
    strcpy(word,"");
	sprintf(word,"%f",number);
}

void convertHourMinuteSecondToMySQLTime(char word[],int hour,int minute,int second)
{
    string10 hourString,minuteString,secondString;
    convertIntToString(hourString,hour);
    convertIntToString(minuteString,minute);
    convertIntToString(secondString,second);
    strcpy(word,"");
    strcat(word,hourString);
    strcat(word,":");
    strcat(word,minuteString);
    strcat(word,":");
    strcat(word,secondString);
    word[strlen(word)] = '\0';
}


void convertHourMinuteSecondTo12HourClockTime(char word[],int hour,int minute,int second)
{
    string10 hourString,minuteString,secondString,modeString;
    if(hour<12)
    {
        strcpy(modeString,"AM");
    }
    else
    {
        strcpy(modeString,"PM");
    }
    convertIntToString(hourString,hour%12);
    convertIntToString(minuteString,minute);
    convertIntToString(secondString,second);
    strcpy(word,"");
    strcat(word,hourString);
    strcat(word,":");
    strcat(word,minuteString);
    strcat(word,":");
    strcat(word,secondString);
    strcat(word," ");
    strcat(word,modeString);
    word[strlen(word)] = '\0';
}

int convertStringToInt(char word[])
{
    return atoi(word);
}


float convertStringToFloat(char word[])
{
    return atof(word);
}

time_t convertTRLStopDateAndTimeToTime_T(TimeRecordingLog trl)
{
    struct tm *timeInfo = NULL;
    time_t time_T = time(NULL);
    timeInfo = localtime(&time_T);
    timeInfo->tm_hour = trl.stopTime.wHour;
    timeInfo->tm_min = trl.stopTime.wMinute;
    timeInfo->tm_sec = trl.stopTime.wSecond;
    timeInfo->tm_mon = getMonthFromMySQLDateString(trl.stopDate)-1;
    timeInfo->tm_mday = getDayFromMySQLDateString(trl.stopDate);
    timeInfo->tm_year = getYearFromMySQLDateString(trl.stopDate)-1900;
    return mktime(timeInfo);
}


time_t convertTRLStartDateAndTimeToTime_T(TimeRecordingLog trl)
{
    struct tm *timeInfo = NULL;
    time_t time_T = time(NULL);
    timeInfo = localtime(&time_T);
    timeInfo->tm_hour = trl.startTime.wHour;
    timeInfo->tm_min = trl.startTime.wMinute;
    timeInfo->tm_sec = trl.startTime.wSecond;
    timeInfo->tm_mon = getMonthFromMySQLDateString(trl.startDate)-1;
    timeInfo->tm_mday = getDayFromMySQLDateString(trl.startDate);
    timeInfo->tm_year = getYearFromMySQLDateString(trl.startDate)-1900;
    return mktime(timeInfo);
}



float convertHourMinuteSecondToMinutes(SYSTEMTIME time)
{
    return (time.wHour*60) + time.wMinute + (time.wSecond/60.0);
}

float getDifferentTimeInMinute(time_t stop, time_t start)
{
    return fabs(difftime(stop,start)/60.0);
}

float getDeltaTimeInMinute(time_t start, time_t stop, float interruption){ /*Unit of time: MINUTES*/
    return (getDifferentTimeInMinute(stop,start)-interruption);
}

float getInterruptionTimeInMinute(time_t start, time_t stop)
{
    return getDifferentTimeInMinute(stop,start);
}


float getInterruptionTimeInMinutesBetweenStopDateAndCurrentTime(TimeRecordingLog trl)
{
    time_t startInterruption,stopInterruption;
    startInterruption = convertTRLStopDateAndTimeToTime_T(trl);
    stopInterruption = time(NULL);
    return getInterruptionTimeInMinute(startInterruption,stopInterruption);
}

int updateActualValueTaskPlanningTemplate(string50 date,string50 phase,Project proj)
{
    float actualCumulativeValue = 0;
    TaskPlanningTemplateLinkedList tpt = NULL,sub = NULL;
    tpt = getAllTPTBasedOnProject(tpt,proj);
    sub = tpt;
    while(sub!=NULL)
    {
        if(stricmp(sub->tpt.taskName,phase)==0)
        {
            strcpy(sub->tpt.actualDate,date);
            sub->tpt.actualValue = sub->tpt.planValue;
            actualCumulativeValue+= sub->tpt.actualValue;
            sub->tpt.actualCumulativeValue = actualCumulativeValue;
            if(!updateTPT(sub->tpt))
            {
                sub = sub->next;
                while(sub!=NULL)
                {
                    sub->tpt.actualCumulativeValue = actualCumulativeValue;
                    if(updateTPT(sub->tpt))
                    {
                        return TRUE;
                    }
                    sub = sub->next;
                }
                break;
            }
            else
            {
                return TRUE;
            }
        }
        actualCumulativeValue+= sub->tpt.actualValue;
        sub = sub->next;
    }
    return updateRealActualValueTaskPlanningTemplate(proj);
}

int updateRealActualValueTaskPlanningTemplate(Project project)
{
    float totalRealActualValue = 0;
    float realActualCumulativeValue = 0;
    TimeRecordingLogLinkedList trl = NULL, subTRL = NULL;
    TaskPlanningTemplateLinkedList tpt = NULL,subTPT = NULL;
    tpt = getAllTPTBasedOnProject(tpt,project);
    subTPT = tpt;
    trl = getAllTRLBasedOnProject(trl,project);
    subTRL = trl;

    while(subTPT!=NULL && subTRL!=NULL)
    {
        if(stricmp(subTPT->tpt.taskName, subTRL->trl.phase)==0)
        {
            subTPT->tpt.realActualValue = subTRL->trl.deltaTime;
            if(updateTPT(subTPT->tpt))
            {
                return TRUE;
            }
        }
        totalRealActualValue+= subTPT->tpt.realActualValue;
        subTRL = subTRL->next;
        subTPT = subTPT->next;
    }
    subTPT = tpt;
    while(subTPT!=NULL)
    {
        subTPT->tpt.realActualCumulativeValue = subTPT->tpt.realActualValue / totalRealActualValue;
        if(updateTPT(subTPT->tpt))
        {
            return TRUE;
        }
        subTPT = subTPT->next;
    }
    return FALSE;
}

int updateSPTActualData(char actualDate[],char actualPhase[],Project proj)
{
    float actualCumulativeMinutes = 0, actualCumulativeValue = 0;
    float actualMinutes = 0;
    SchedulePlanningTemplateLinkedList spt = NULL;
    TaskPlanningTemplateLinkedList tpt = NULL;
    TimeRecordingLogLinkedList trl = NULL;
    spt = getAllSPTBasedOnProject(spt,proj);
    if(spt==NULL)
    {
        return TRUE;
    }
    while(spt!=NULL)
    {
        //if(stricmp(spt->spt.planDate,actualDate)==0)
        //{
            trl = getAllTRLBasedOnStartDateAndProject(trl,proj,spt->spt.planDate);
            if(trl==NULL)
            {
                actualMinutes = 0;
            }
            else
            {
                while(trl!=NULL)
                {
                    actualMinutes+= trl->trl.deltaTime;
                    trl = trl->next;
                }
            }
            spt->spt.actualMinutes = actualMinutes;
            actualCumulativeMinutes+= spt->spt.actualMinutes;
            spt->spt.actualCumulativeMinutes = actualCumulativeMinutes;
            tpt = getTPTBasedOnPhaseAndProject(tpt,proj,actualPhase);
            if(tpt!=NULL)
            {
                if(stricmp(spt->spt.planDate,actualDate)==0)
                {
                    spt->spt.actualCumulativeValue = tpt->tpt.actualCumulativeValue;
                }
                actualCumulativeValue = spt->spt.actualCumulativeValue;
                spt->spt.adjustedEarnedValue = getSPTAdjustedEarnedValue(spt->spt.planCumulativeValue, spt->spt.actualCumulativeValue);
                if(!updateSPT(spt->spt))
                {
                    spt = spt->next;
                    while(spt!=NULL)
                    {
                        actualCumulativeMinutes+= spt->spt.actualCumulativeMinutes;
                        spt->spt.actualCumulativeMinutes = actualCumulativeMinutes;
                        spt->spt.actualCumulativeValue = actualCumulativeValue;
                        spt->spt.adjustedEarnedValue = getSPTAdjustedEarnedValue(spt->spt.planCumulativeValue, spt->spt.actualCumulativeValue);
                        if(updateSPT(spt->spt))
                        {
                            return TRUE;
                        }
                        spt = spt->next;
                    }
                    break;
                }
                else
                {
                    return TRUE;
                }
            }
            else
            {
                return TRUE;
            }
        //}
        actualCumulativeMinutes = spt->spt.actualCumulativeMinutes;
        spt = spt->next;
    }
    return FALSE;
}

float getSPTPlanCumulativeValue(float sptPlanCumulativeMinutes,Project proj)
{
    float sptPlanCumulativeValue = 0;
    TaskPlanningTemplateLinkedList tpt = NULL;
    tpt = getAllTPTBasedOnProject(tpt,proj);
    while(tpt!=NULL)
    {
        if(tpt->tpt.planCumulativeMinutes<=sptPlanCumulativeMinutes)
        {
            sptPlanCumulativeValue = tpt->tpt.planCumulativeValue;
        }
        tpt = tpt->next;
    }
    return sptPlanCumulativeValue;
}

float getSPTAdjustedEarnedValue(float planCumulativeValue,float actualCumulativeValue)
{
    return (actualCumulativeValue - planCumulativeValue);
}


int doSizeEstimatingTemplateComputations(SizeEstimatingTemplate set)
{
    SETProjectedLOCLinkedList setProjectedLOC = NULL;
    SETReusedFunctionLinkedList reusedFunction = NULL;
    float totalBA = 0;
    float totalNF = 0;
    float totalR = 0;
    //Get Total Base Addition (BA)
    setProjectedLOC = NULL;
    setProjectedLOC = getAllSETProjectedLOCBasedOnSETAndTypeOfProjectedLOC(setProjectedLOC,set,TYPE_OF_PROJECTEC_LOC_BA);
    while(setProjectedLOC!=NULL)
    {
        totalBA+= setProjectedLOC->setProjectedLOC.setProjectedLOCLOC;
        setProjectedLOC = setProjectedLOC->next;
    }
    //Get Total New Function (NF)
    setProjectedLOC = NULL;
    setProjectedLOC = getAllSETProjectedLOCBasedOnSETAndTypeOfProjectedLOC(setProjectedLOC,set,TYPE_OF_PROJECTEC_LOC_NF);
    while(setProjectedLOC!=NULL)
    {
        totalNF+= setProjectedLOC->setProjectedLOC.setProjectedLOCLOC;
        setProjectedLOC = setProjectedLOC->next;
    }
    //Get Total Reused Function (R)
    reusedFunction = NULL;
    reusedFunction = getAllSETReusedFunctionBasedOnSET(reusedFunction,set);
    while(reusedFunction!=NULL)
    {
        totalR+= reusedFunction->setReusedFunction.reusedFunctionLOC;
        reusedFunction = reusedFunction->next;
    }

    //Compute The Rest
    set.projectedLOC = totalBA+totalNF;
    set.estimatedNewAndChangedLOC = set.b0 + (set.b1*(set.projectedLOC+set.baseProgramLOCModified));
    set.estimatedTotalLOC = set.estimatedNewAndChangedLOC + set.baseProgamBaseSize - set.baseProgramLOCDeleted - set.baseProgramLOCModified + totalR;
    set.estimatedTotalNewReused = totalR;
    set.predictionRange = 0;
    set.upperPredictionInterval = set.estimatedNewAndChangedLOC + set.predictionRange;
    set.lowerPredictionInterval = set.estimatedNewAndChangedLOC - set.predictionRange;
    if(set.lowerPredictionInterval<0)
    {
        set.lowerPredictionInterval = 0;
    }
    set.predictionIntervalPercent = 0;
    return updateSET(set);
}



ProjectPlanSummary initializeAllPPSAttributesToZero()
{
    ProjectPlanSummary pps;

    pps.summaryLOCPerHour = 0;
    pps.summaryPlanTime = 0;
    pps.summaryActualTime = 0;
    pps.summaryCPI = 0;
    pps.summaryPercentReused = 0;
    pps.summaryPercentNewReused = 0;

    pps.programSizeBase = 0;
    pps.programSizeDeleted = 0;
    pps.programSizeModified = 0;
    pps.programSizeReused = 0;
    pps.programSizeNewAndChanged = 0;
    pps.programSizeTotalLOC = 0;
    pps.programSizeNewReused = 0;
    pps.programSizeAdded = 0;

    pps.trlPlanning = 0;
    pps.trlDesign = 0;
    pps.trlCode = 0;
    pps.trlCompile = 0;
    pps.trlTest = 0;
    pps.trlPostmortem = 0;

    pps.injectPlanning = 0;
    pps.injectDesign = 0;
    pps.injectCode = 0;
    pps.injectCompile = 0;
    pps.injectTest = 0;

    pps.removePlanning = 0;
    pps.removeDesign = 0;
    pps.removeCode = 0;
    pps.removeCompile = 0;
    pps.removeTest = 0;
    pps.removeAfterDevelopment = 0;

    return pps;

}


ProjectPlanSummary fillPlannedProjectPlanSummary(Project proj)
{
    ProjectPlanSummary planned = initializeAllPPSAttributesToZero();
    planned.programSizeBase = 0;
    planned.programSizeDeleted = 0;
    planned.programSizeModified = 0;
    planned.programSizeReused = 0;
    planned.programSizeNewAndChanged = 0;
    planned.programSizeTotalLOC = 0;
    planned.programSizeNewReused = 0;
    planned.programSizeAdded = 0;

    SizeEstimatingTemplateLinkedList set = NULL; //Program Size: Planned
    TaskPlanningTemplateLinkedList tpt = NULL; //Time in Phase: Planned
    //TimeRecordingLogLinkedList trl; //Time in Phase: Actual
    //DefectRecordingLogLinkedList drl; //Defect Inject and Remove: Actual

    //Program Size
    set = getAllSETBasedOnProjectAndType(set,proj,SET_TYPE_PLAN);
    if(set!=NULL)
    {
        planned.programSizeBase = set->set.baseProgamBaseSize;
        planned.programSizeDeleted = set->set.baseProgramLOCDeleted;
        planned.programSizeModified = set->set.baseProgramLOCModified;
        planned.programSizeReused = set->set.estimatedTotalNewReused;
        planned.programSizeNewAndChanged = set->set.estimatedNewAndChangedLOC;
        planned.programSizeTotalLOC = set->set.estimatedTotalLOC;
        planned.programSizeNewReused = set->set.estimatedTotalNewReused;
        planned.programSizeAdded = set->set.estimatedNewAndChangedLOC - set->set.baseProgramLOCModified;
    }

    //Time in Phase
    tpt = getAllTPTBasedOnProject(tpt,proj);
    if(tpt!=NULL)
    {
        planned.trlPlanning = tpt->tpt.planMinutes; tpt = tpt->next;
        planned.trlDesign = tpt->tpt.planMinutes; tpt = tpt->next;
        planned.trlCode = tpt->tpt.planMinutes; tpt = tpt->next;
        planned.trlCompile = tpt->tpt.planMinutes; tpt = tpt->next;
        planned.trlTest = tpt->tpt.planMinutes; tpt = tpt->next;
        planned.trlPostmortem = tpt->tpt.planMinutes; tpt = tpt->next;
    }
    else
    {
        planned.trlPlanning = 0;
        planned.trlDesign = 0;
        planned.trlCode = 0;
        planned.trlCompile = 0;
        planned.trlTest = 0;
        planned.trlPostmortem = 0;
    }

    //Summary
    planned.summaryPlanTime = planned.trlPlanning+planned.trlDesign+planned.trlCode+planned.trlCompile+planned.trlTest+planned.trlPostmortem;
    if(planned.trlCode==0)
    {
        planned.summaryLOCPerHour = (planned.programSizeNewAndChanged / 1) *60;
    }
    else
    {
        planned.summaryLOCPerHour = (planned.programSizeNewAndChanged / planned.trlCode) *60;
    }
    if(planned.programSizeTotalLOC==0)
    {
        planned.summaryPercentReused = (planned.programSizeReused / 1) * 100;
        planned.summaryPercentNewReused = (planned.programSizeNewReused / 1) * 100;
    }
    else
    {
        planned.summaryPercentReused = (planned.programSizeReused / planned.programSizeTotalLOC) * 100;
        planned.summaryPercentNewReused = (planned.programSizeNewReused / planned.programSizeTotalLOC) * 100;
    }

    strcpy(planned.ppsType,PPS_TYPE_PLAN);
    return planned;
}



ProjectPlanSummary fillActualProjectPlanSummary(Project proj)
{
    ProjectPlanSummary pps = initializeAllPPSAttributesToZero();
    pps.programSizeBase = 0;
    pps.programSizeDeleted = 0;
    pps.programSizeModified = 0;
    pps.programSizeReused = 0;
    pps.programSizeNewAndChanged = 0;
    pps.programSizeTotalLOC = 0;
    pps.programSizeNewReused = 0;
    pps.programSizeAdded = 0;
    //SizeEstimatingTemplateLinkedList set; //Program Size: Planned
    //TaskPlanningTemplateLinkedList tpt; //Time in Phase: Planned
    SizeEstimatingTemplateLinkedList set = NULL; //Program Size: Actual
    TimeRecordingLogLinkedList trl = NULL; //Time in Phase: Actual
    DefectRecordingLogLinkedList drl = NULL, tempDRL = NULL; //Defect Inject and Remove: Actual

    //Program Size
    set = getAllSETBasedOnProjectAndType(set,proj,SET_TYPE_ACTUAL);
    if(set!=NULL)
    {
        pps.programSizeBase = set->set.baseProgamBaseSize;
        pps.programSizeDeleted = set->set.baseProgramLOCDeleted;
        pps.programSizeModified = set->set.baseProgramLOCModified;
        pps.programSizeReused = set->set.estimatedTotalNewReused;
        pps.programSizeNewAndChanged = set->set.estimatedNewAndChangedLOC;
        pps.programSizeTotalLOC = set->set.estimatedTotalLOC;
        pps.programSizeNewReused = set->set.estimatedTotalNewReused;
        pps.programSizeAdded = set->set.estimatedNewAndChangedLOC - set->set.baseProgramLOCModified;
    }


    //Time in Phase
    trl = getAllTRLBasedOnProject(trl,proj);
    pps.trlPlanning = 0;
    pps.trlDesign = 0;
    pps.trlCode = 0;
    pps.trlCompile = 0;
    pps.trlTest = 0;
    pps.trlPostmortem = 0;
    while(trl!=NULL)
    {
        if(stricmp(trl->trl.phase,PLANNING_PHASE)==0)
        {
            pps.trlPlanning = trl->trl.deltaTime;
        }
        else if(stricmp(trl->trl.phase,DESIGN_PHASE)==0)
        {
            pps.trlDesign = trl->trl.deltaTime;
        }
        else if(stricmp(trl->trl.phase,CODING_PHASE)==0)
        {
            pps.trlCode = trl->trl.deltaTime;
        }
        else if(stricmp(trl->trl.phase,COMPILE_PHASE)==0)
        {
            pps.trlCompile = trl->trl.deltaTime;
        }
        else if(stricmp(trl->trl.phase,TESTING_PHASE)==0)
        {
            pps.trlTest = trl->trl.deltaTime;
        }
        else if(stricmp(trl->trl.phase,POSTMORTEM_PHASE)==0)
        {
            pps.trlPostmortem = trl->trl.deltaTime;
        }
        trl = trl->next;
    }

    //Defect: Inject
    drl = getAllDRLBasedOnProject(drl,proj);
    tempDRL = drl;
    pps.injectPlanning = 0;
    pps.injectDesign = 0;
    pps.injectCode = 0;
    pps.injectCompile = 0;
    pps.injectTest = 0;
    while(tempDRL!=NULL)
    {
        if(stricmp(tempDRL->drl.inject,PLANNING_PHASE)==0)
        {
            pps.injectPlanning++;
        }
        else if(stricmp(tempDRL->drl.inject,DESIGN_PHASE)==0)
        {
            pps.injectDesign++;
        }
        else if(stricmp(tempDRL->drl.inject,CODING_PHASE)==0)
        {
            pps.injectCode++;
        }
        else if(stricmp(tempDRL->drl.inject,COMPILE_PHASE)==0)
        {
            pps.injectCompile++;
        }
        else if(stricmp(tempDRL->drl.inject,TESTING_PHASE)==0)
        {
            pps.injectTest++;
        }
        tempDRL = tempDRL->next;
    }

    //Defect: Remove
    tempDRL = drl;
    pps.removePlanning = 0;
    pps.removeDesign = 0;
    pps.removeCode = 0;
    pps.removeCompile = 0;
    pps.removeTest = 0;
    pps.removeAfterDevelopment = 0;
    while(tempDRL!=NULL)
    {
        if(stricmp(tempDRL->drl.remove,PLANNING_PHASE)==0)
        {
            pps.removePlanning++;
        }
        else if(stricmp(tempDRL->drl.remove,DESIGN_PHASE)==0)
        {
            pps.removeDesign++;
        }
        else if(stricmp(tempDRL->drl.remove,CODING_PHASE)==0)
        {
            pps.removeCode++;
        }
        else if(stricmp(tempDRL->drl.remove,COMPILE_PHASE)==0)
        {
            pps.removeCompile++;
        }
        else if(stricmp(tempDRL->drl.remove,TESTING_PHASE)==0)
        {
            pps.removeTest++;
        }
        else if(stricmp(tempDRL->drl.remove,AFTER_DEVELOPMENT_PHASE)==0)
        {
            pps.removeAfterDevelopment++;
        }
        tempDRL = tempDRL->next;
    }

    //Summary
    pps.summaryActualTime = pps.trlPlanning+pps.trlDesign+pps.trlCode+pps.trlCompile+pps.trlTest+pps.trlPostmortem;
    if(pps.trlCode==0)
    {
        pps.summaryLOCPerHour = (pps.programSizeNewAndChanged / 1) *60;
    }
    else
    {
        pps.summaryLOCPerHour = (pps.programSizeNewAndChanged / pps.trlCode) *60;
    }
    if(pps.programSizeTotalLOC==0)
    {
        pps.summaryPercentReused = (pps.programSizeReused / 1) * 100;
        pps.summaryPercentNewReused = (pps.programSizeNewReused / 1) * 100;
    }
    else
    {
        pps.summaryPercentReused = (pps.programSizeReused / pps.programSizeTotalLOC) * 100;
        pps.summaryPercentNewReused = (pps.programSizeNewReused / pps.programSizeTotalLOC) * 100;
    }

    strcpy(pps.ppsType,PPS_TYPE_ACTUAL);
    return pps;
}




ProjectPlanSummary fillToDateProjectPlanSummary(Project proj,ProjectPlanSummary plan,ProjectPlanSummary actual)
{
    int phase = 1;
    Project prevProj = proj;
    ProjectPlanSummaryLinkedList temp = NULL;
    ProjectPlanSummary pps = initializeAllPPSAttributesToZero();
    ProjectPlanSummary prevPPS = initializeAllPPSAttributesToZero();

    if(convertStringToInt(proj.previousProjectID)<0)
    {
        prevProj = proj;
        prevPPS = initializeAllPPSAttributesToZero();
    }
    else
    {
        prevProj = getProjectByID(proj.previousProjectID);
        temp = getAllPPSBasedOnProjectAndPPSType(temp,prevProj,PPS_TYPE_TO_DATE);
        if(temp!=NULL)
        {
            prevPPS = temp->pps;
        }
    }

    //Program Size
    pps.programSizeReused = actual.programSizeReused + prevPPS.programSizeReused;
    pps.programSizeNewAndChanged = actual.programSizeNewAndChanged + prevPPS.programSizeNewAndChanged;
    pps.programSizeTotalLOC = actual.programSizeTotalLOC + prevPPS.programSizeTotalLOC;
    pps.programSizeNewReused = actual.programSizeNewReused + prevPPS.programSizeNewReused;

    //Time in Phase
    pps.trlPlanning = actual.trlPlanning + prevPPS.trlPlanning;
    pps.trlDesign = actual.trlDesign + prevPPS.trlDesign;
    pps.trlCode = actual.trlCode + prevPPS.trlCode;
    pps.trlCompile = actual.trlCompile + prevPPS.trlCompile;
    pps.trlTest = actual.trlTest + prevPPS.trlTest;
    pps.trlPostmortem = actual.trlPostmortem + prevPPS.trlPostmortem;


    //Defect: Inject
    pps.injectPlanning = actual.injectPlanning + prevPPS.injectPlanning;
    pps.injectDesign = actual.injectDesign + prevPPS.injectDesign;
    pps.injectCode = actual.injectCode + prevPPS.injectCode;
    pps.injectCompile = actual.injectCompile + prevPPS.injectCompile;
    pps.injectTest = actual.injectTest + prevPPS.injectTest;


    //Defect: Remove
    pps.removePlanning = actual.removePlanning + prevPPS.removePlanning;
    pps.removeDesign = actual.removeDesign + prevPPS.removeDesign;
    pps.removeCode = actual.removeCode + prevPPS.removeCode;
    pps.removeCompile = actual.removeCompile + prevPPS.removeCompile;
    pps.removeTest = actual.removeTest + prevPPS.removeTest;
    pps.removeAfterDevelopment = actual.removeAfterDevelopment + prevPPS.removeAfterDevelopment;

    //Summary
    pps.summaryPlanTime = plan.summaryPlanTime + prevPPS.summaryPlanTime;
    pps.summaryActualTime = actual.summaryActualTime + prevPPS.summaryActualTime;
    pps.summaryLOCPerHour =  actual.summaryLOCPerHour + prevPPS.summaryLOCPerHour;
    pps.summaryPercentReused =  actual.summaryPercentReused + prevPPS.summaryPercentReused;
    pps.summaryPercentNewReused =  actual.summaryPercentNewReused + prevPPS.summaryPercentNewReused;
    if(pps.summaryActualTime==0)
    {
        pps.summaryCPI =  pps.summaryPlanTime / 1;
    }
    else
    {
        pps.summaryCPI =  pps.summaryPlanTime / pps.summaryActualTime;
    }
    strcpy(pps.ppsType,PPS_TYPE_TO_DATE);
    return pps;
}



ProjectPlanSummary fillToDatePercentProjectPlanSummary(ProjectPlanSummary toDate)
{
    float trlTotal = 1,injectTotal = 1,removeTotal = 1;
    ProjectPlanSummary pps = initializeAllPPSAttributesToZero();



    //Time in Phase
    trlTotal = toDate.trlPlanning+toDate.trlDesign+toDate.trlCode+toDate.trlCompile+toDate.trlTest+toDate.trlPostmortem;
    if(trlTotal==0)
    {
        trlTotal = 1;
    }
    pps.trlPlanning = 0+(toDate.trlPlanning/trlTotal) * 100;
    pps.trlDesign = 0+(toDate.trlDesign/trlTotal) * 100;
    pps.trlCode = 0+(toDate.trlCode/trlTotal) * 100;
    pps.trlCompile = 0+(toDate.trlCompile/trlTotal) * 100;
    pps.trlTest = 0+(toDate.trlTest/trlTotal) * 100;
    pps.trlPostmortem = 0+(toDate.trlPostmortem/trlTotal) * 100;


    //Defect: Inject
    injectTotal = toDate.injectPlanning+toDate.injectDesign+toDate.injectCode+toDate.injectCompile+toDate.injectTest;
    if(injectTotal==0)
    {
        injectTotal = 1;
    }
    pps.injectPlanning = 0+(toDate.injectPlanning/injectTotal) * 100;
    pps.injectDesign = 0+(toDate.injectDesign/injectTotal) * 100;
    pps.injectCode = 0+(toDate.injectCode/injectTotal) * 100;
    pps.injectCompile = 0+(toDate.injectCompile/injectTotal) * 100;
    pps.injectTest = 0+(toDate.injectTest/injectTotal) * 100;


    //Defect: Remove
    removeTotal = toDate.removePlanning+toDate.removeDesign+toDate.removeCode+toDate.removeCompile+toDate.removeTest;
    if(removeTotal==0)
    {
        removeTotal = 1;
    }
    pps.removePlanning = 0+(toDate.removePlanning/removeTotal) * 100;
    pps.removeDesign = 0+(toDate.removeDesign/removeTotal) * 100;
    pps.removeCode = 0+(toDate.removeCode/removeTotal) * 100;
    pps.removeCompile = 0+(toDate.removeCompile/removeTotal) * 100;
    pps.removeTest = 0+(toDate.removeTest/removeTotal) * 100;

    pps.summaryActualTime = pps.trlPlanning+pps.trlDesign+pps.trlCode+pps.trlCompile+pps.trlTest+pps.trlPostmortem;

    strcpy(pps.ppsType,"ToDatePercentage");
    return pps;
}




/*MySQL Functions*/

void showMySQLDatabaseError()
{
    if(MYSQL_DEBUG)
    {
        printf("\n\nERROR: %s\n", mysql_error(conn));
    }
    else
    {
        printf("\n\nERROR: Database Error\n");
    }
    getch();
}

int connectMySQLDatabase()
{
    /* initialize connection handler */
    conn = mysql_init (NULL);

    /* connect to server */
    if(!mysql_real_connect (conn, opt_host_name, opt_user_name, opt_password,
    opt_db_name, opt_port_num, opt_socket_name, opt_flags)){
        //Error
        return FALSE;
    }
    //SUCCESS
    return TRUE;
}

int disconnectMySQLDatabase()
{
    /* disconnect from server */
    mysql_close(conn);
}


boolean userExist(User user)
{
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    int exist = FALSE;
    string300 script = "select * from users where firstName = '";
    strcat(script,user.firstName);
    strcat(script,"' and middleName = '");
    strcat(script,user.middleName);
    strcat(script,"' and lastName = '");
    strcat(script,user.lastName);
    strcat(script,"'");

    if(mysql_query(conn, script)) //execute the script
    {
        showMySQLDatabaseError();
        exist = TRUE;
    }
    else
    {
        rs = mysql_use_result(conn); // grab the result
        while((row = mysql_fetch_row(rs)) != NULL) //get each row
        {
            exist = TRUE;
        }
    }
    return exist;
}




boolean userEmailAndNameExist(User user[])
{
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    int exist = FALSE;
    User tempUser;
    string1000 script = "select * from users where firstName = '";
    strcat(script,user[0].firstName);
    strcat(script,"' and middleName = '");
    strcat(script,user[0].middleName);
    strcat(script,"' and lastName = '");
    strcat(script,user[0].lastName);
    strcat(script,"' and emailAddress = '");
    strcat(script,user[0].emailAddress);
    strcat(script,"'");

    if(mysql_query(conn, script)) //execute the script
    {
        showMySQLDatabaseError();
        exist = FALSE;
    }
    else
    {
        rs = mysql_use_result(conn); // grab the result
        while((row = mysql_fetch_row(rs)) != NULL) //get each row
        {
            strcpy(user[0].id,row[0]);
            strcpy(tempUser.firstName,row[1]);
            strcpy(tempUser.middleName,row[2]);
            strcpy(tempUser.lastName,row[3]);
            strcpy(tempUser.password,row[4]);
            strcpy(tempUser.emailAddress,row[5]);
            strcpy(tempUser.userCurrentlyUsed,row[6]);
            strcpy(tempUser.userActive,row[7]);
            decryptPassword(tempUser.password);
            exist = TRUE;
        }
        if(exist)
        {
            if((stricmp(user[0].firstName,tempUser.firstName)==0) &&
               (stricmp(user[0].middleName,tempUser.middleName)==0) &&
               (stricmp(user[0].lastName,tempUser.lastName)==0) &&
               (strcmp(user[0].emailAddress,tempUser.emailAddress)==0) )
            {
                strcpy(user[0].firstName,tempUser.firstName);
                strcpy(user[0].middleName,tempUser.middleName);
                strcpy(user[0].lastName,tempUser.lastName);
                strcpy(user[0].password,tempUser.password);
                strcpy(user[0].emailAddress,tempUser.emailAddress);
                strcpy(user[0].userCurrentlyUsed,tempUser.userCurrentlyUsed);
                strcpy(user[0].userActive,tempUser.userActive);
                return TRUE;
            }
        }
    }
    return exist;
}




boolean isUserCurrentlyUsed(User user)
{
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    int exist = FALSE;
    string300 script = "select * from users where firstName = '";
    strcat(script,user.firstName);
    strcat(script,"' and middleName = '");
    strcat(script,user.middleName);
    strcat(script,"' and lastName = '");
    strcat(script,user.lastName);
    strcat(script,"' and userCurrentlyUsed = 'true' ");

    if(mysql_query(conn, script)) //execute the script
    {
        showMySQLDatabaseError();
        exist = TRUE;
    }
    else
    {
        rs = mysql_use_result(conn); // grab the result
        while((row = mysql_fetch_row(rs)) != NULL) //get each row
        {
            exist = TRUE;
        }
    }
    return exist;
}


int registerUser(User user)
{
    int error = 0;
    encryptPassword(user.password);
    string300 script = "INSERT INTO users (firstName,middleName,lastName,password,emailAddress,userCurrentlyUsed,userActive) VALUES ('";
    makeFirstLetterCapital(user.firstName);
    makeFirstLetterCapital(user.middleName);
    makeFirstLetterCapital(user.lastName);
    strcat(script,user.firstName);
    strcat(script,"','");
    strcat(script,user.middleName);
    strcat(script,"','");
    strcat(script,user.lastName);
    strcat(script,"','");
    strcat(script,user.password);
    strcat(script,"','");
    strcat(script,user.emailAddress);
    strcat(script,"','");
    strcat(script,user.userCurrentlyUsed);
    strcat(script,"','");
    strcat(script,user.userActive);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}



boolean authenticate(User user[])
{
    int error = FALSE;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    User tempUser;
    string300 script = "select * from users where firstName = '";
    strcat(script,user[0].firstName);
    strcat(script,"' and middleName = '");
    strcat(script,user[0].middleName);
    strcat(script,"' and lastName = '");
    strcat(script,user[0].lastName);
    strcat(script,"'");

    error = mysql_query(conn, script); //execute the script
    if(error)
    {
        showMySQLDatabaseError();
        return FALSE;
    }
    rs = mysql_use_result(conn); // grab the result
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        strcpy(user[0].id,row[0]);
        strcpy(tempUser.firstName,row[1]);
        strcpy(tempUser.middleName,row[2]);
        strcpy(tempUser.lastName,row[3]);
        strcpy(tempUser.password,row[4]);
        strcpy(tempUser.emailAddress,row[5]);
        strcpy(tempUser.userCurrentlyUsed,row[6]);
        strcpy(tempUser.userActive,row[7]);
        decryptPassword(tempUser.password);
    }
    if((stricmp(user[0].firstName,tempUser.firstName)==0) &&
       (stricmp(user[0].middleName,tempUser.middleName)==0) &&
       (stricmp(user[0].lastName,tempUser.lastName)==0) &&
       (strcmp(user[0].password,tempUser.password)==0) )
    {
        strcpy(user[0].firstName,tempUser.firstName);
        strcpy(user[0].middleName,tempUser.middleName);
        strcpy(user[0].lastName,tempUser.lastName);
        strcpy(user[0].password,tempUser.password);
        strcpy(user[0].emailAddress,tempUser.emailAddress);
        strcpy(user[0].userCurrentlyUsed,tempUser.userCurrentlyUsed);
        strcpy(user[0].userActive,tempUser.userActive);
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}




int updateUser(User user)
{
    int error = 0;
    string50 tempPassword;
    strcpy(tempPassword,user.password);
    encryptPassword(tempPassword);
    string300 script = "update users set firstName = '";
    strcat(script,user.firstName);
    strcat(script,"' , middleName = '");
    strcat(script,user.middleName);
    strcat(script,"' , lastName = '");
    strcat(script,user.lastName);
    strcat(script,"' , password = '");
    strcat(script,tempPassword);
    strcat(script,"' , emailAddress = '");
    strcat(script,user.emailAddress);
    strcat(script,"' , userCurrentlyUsed = '");
    strcat(script,user.userCurrentlyUsed);
    strcat(script,"' , userActive = '");
    strcat(script,user.userActive);
    strcat(script,"'  where userID = '");
    strcat(script,user.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




int addProject(Project project)
{
    int error = 0;
    string300 script = "insert into project (userID,projectDate,programNumber,program,language,professor,previousProjectID,projectActive) values ('";
    strcat(script,project.user.id);
    strcat(script,"','");
    strcat(script,project.date);
    strcat(script,"','");
    strcat(script,project.programNumber);
    strcat(script,"','");
    strcat(script,project.program);
    strcat(script,"','");
    strcat(script,project.language);
    strcat(script,"','");
    strcat(script,project.professor);
    strcat(script,"','");
    strcat(script,project.previousProjectID);
    strcat(script,"','");
    strcat(script,project.projectActive);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}


Project getProjectByID(char id[])
{
    Project project;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "select * from project where projectID = '";
    strcat(script,id);
    strcat(script,"' and projectActive = 'True' ");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        strcpy(project.id,row[0]);
        strcpy(project.user.id,row[1]);
        strcpy(project.date,row[2]);
        strcpy(project.programNumber,row[3]);
        strcpy(project.program,row[4]);
        strcpy(project.language,row[5]);
        strcpy(project.professor,row[6]);
        strcpy(project.previousProjectID,row[7]);
        strcpy(project.projectActive,row[8]);
    }
    return project;
}



Project getProjectByProgramNumberAndUser(char programNumber[],User user)
{
    Project project;
    strcpy(project.programNumber,"");
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "select * from project where programNumber = '";
    strcat(script,programNumber);
    strcat(script,"' and userID = ' ");
    strcat(script,user.id);
    strcat(script,"' and projectActive = 'True' ");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        strcpy(project.id,row[0]);
        strcpy(project.user.id,row[1]);
        strcpy(project.date,row[2]);
        strcpy(project.programNumber,row[3]);
        strcpy(project.program,row[4]);
        strcpy(project.language,row[5]);
        strcpy(project.professor,row[6]);
        strcpy(project.previousProjectID,row[7]);
        strcpy(project.projectActive,row[8]);
    }
    return project;
}


Project getRecentCreatedProject()
{
    Project project;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "select * from project where projectActive = 'true' order by projectID desc";
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        strcpy(project.id,row[0]);
        strcpy(project.user.id,row[1]);
        strcpy(project.date,row[2]);
        strcpy(project.programNumber,row[3]);
        strcpy(project.program,row[4]);
        strcpy(project.language,row[5]);
        strcpy(project.professor,row[6]);
        strcpy(project.previousProjectID,row[7]);
        strcpy(project.projectActive,row[8]);
    }
    return project;
}

ProjectLinkedList getAllProjectFromUser(ProjectLinkedList proj,User user)
{
    ProjectLinkedList projNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "select * from project where userID = '";
    strcat(script,user.id);
    strcat(script,"' and projectActive = 'True' order by programNumber");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    proj = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        projNew = malloc(sizeof(struct ProjectLinked));
        projNew->prev=NULL;
        projNew->next=NULL;
        strcpy(projNew->project.id,row[0]);
        strcpy(projNew->project.user.id,row[1]);
        strcpy(projNew->project.date,row[2]);
        strcpy(projNew->project.programNumber,row[3]);
        strcpy(projNew->project.program,row[4]);
        strcpy(projNew->project.language,row[5]);
        strcpy(projNew->project.professor,row[6]);
        strcpy(projNew->project.previousProjectID,row[7]);
        strcpy(projNew->project.projectActive,row[8]);
        if(proj==NULL)
        {
            proj = projNew;
            sub = proj;
        }
        else
        {
            sub->next = projNew;
            projNew ->prev = sub;
            sub = sub->next;
        }
    }
    return proj;
}


int updateProject(Project project)
{
    int error = 0;
    string300 script = "update project set programNumber = '";
    strcat(script,project.programNumber);
    strcat(script,"' , program = '");
    strcat(script,project.program);
    strcat(script,"' , language = '");
    strcat(script,project.language);
    strcat(script,"' , professor = '");
    strcat(script,project.professor);
    strcat(script,"' , previousProjectID = '");
    strcat(script,project.previousProjectID);
    strcat(script,"' , projectActive = '");
    strcat(script,project.projectActive);
    strcat(script,"'  where projectID = '");
    strcat(script,project.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}



int addTRL(TimeRecordingLog trl)
{
    int error = 0;
    string50 tempStart,tempStop,tempInterruptionTime,tempDeltaTime;
    convertHourMinuteSecondToMySQLTime(tempStart,trl.startTime.wHour,trl.startTime.wMinute,trl.startTime.wSecond);
    convertHourMinuteSecondToMySQLTime(tempStop,trl.stopTime.wHour,trl.stopTime.wMinute,trl.stopTime.wSecond);
    convertFloatToString(tempInterruptionTime,trl.interruptonTime);
    convertFloatToString(tempDeltaTime,trl.deltaTime);
    string300 script = "insert into trl (projectID,trlStartDate,trlStopDate,startTime,stopTime,interruptionTime,deltaTime,phase,comment) values ('";
    strcat(script,trl.project.id);
    strcat(script,"','");
    strcat(script,trl.startDate);
    strcat(script,"','");
    strcat(script,trl.stopDate);
    strcat(script,"','");
    strcat(script,tempStart);
    strcat(script,"','");
    strcat(script,tempStop);
    strcat(script,"','");
    strcat(script,tempInterruptionTime);
    strcat(script,"','");
    strcat(script,tempDeltaTime);
    strcat(script,"','");
    strcat(script,trl.phase);
    strcat(script,"','");
    strcat(script,trl.comment);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}


TimeRecordingLogLinkedList getAllTRLBasedOnProject(TimeRecordingLogLinkedList trl, Project proj)
{
    TimeRecordingLogLinkedList trlNew,sub;
    string50 tempStartTime,tempStopTime;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "SELECT * FROM trl where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' order by trlID");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    trl = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        trlNew = malloc(sizeof(struct TimeRecordingLogLinked));
        trlNew->prev=NULL;
        trlNew->next=NULL;
        strcpy(trlNew->trl.id,row[0]);
        strcpy(trlNew->trl.project.id,row[1]);
        strcpy(trlNew->trl.startDate,row[2]);
        strcpy(trlNew->trl.stopDate,row[3]);
        strcpy(tempStartTime,row[4]);
        strcpy(tempStopTime,row[5]);
        trlNew->trl.interruptonTime = convertStringToFloat(row[6]);
        trlNew->trl.deltaTime = convertStringToFloat(row[7]);
        strcpy(trlNew->trl.phase,row[8]);
        strcpy(trlNew->trl.comment,row[9]);
        trlNew->trl.startTime.wHour = getHourFromMySQLTimeString(tempStartTime);
        trlNew->trl.startTime.wMinute = getMinuteFromMySQLTimeString(tempStartTime);
        trlNew->trl.startTime.wSecond = getSecondFromMySQLTimeString(tempStartTime);
        trlNew->trl.stopTime.wHour = getHourFromMySQLTimeString(tempStopTime);
        trlNew->trl.stopTime.wMinute = getMinuteFromMySQLTimeString(tempStopTime);
        trlNew->trl.stopTime.wSecond = getSecondFromMySQLTimeString(tempStopTime);
        if(trl==NULL)
        {
            trl = trlNew;
            sub = trl;
        }
        else
        {
            sub->next = trlNew;
            trlNew ->prev = sub;
            sub = sub->next;
        }
    }
    return trl;
}

float countTRL(Project proj)
{
    float trlNumberCount = 0;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "select count(trlID) as 'trlNumberCount' from trl where projectID = '";
    strcat(script,proj.id);
    strcat(script,"'");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        trlNumberCount = convertStringToFloat(row[0]);
    }
    return trlNumberCount;
}

TimeRecordingLogLinkedList getAllTRLBasedOnStartDateAndProject(TimeRecordingLogLinkedList trl,Project proj,char startDate[])
{
    TimeRecordingLogLinkedList trlNew,sub;
    string50 tempStartTime,tempStopTime;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "SELECT * FROM trl where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' and trlStartDate = '");
    strcat(script,startDate);
    strcat(script,"' order by trlID");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    trl = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        trlNew = malloc(sizeof(struct TimeRecordingLogLinked));
        trlNew->prev=NULL;
        trlNew->next=NULL;
        strcpy(trlNew->trl.id,row[0]);
        strcpy(trlNew->trl.project.id,row[1]);
        strcpy(trlNew->trl.startDate,row[2]);
        strcpy(trlNew->trl.stopDate,row[3]);
        strcpy(tempStartTime,row[4]);
        strcpy(tempStopTime,row[5]);
        trlNew->trl.interruptonTime = convertStringToFloat(row[6]);
        trlNew->trl.deltaTime = convertStringToFloat(row[7]);
        strcpy(trlNew->trl.phase,row[8]);
        strcpy(trlNew->trl.comment,row[9]);
        trlNew->trl.startTime.wHour = getHourFromMySQLTimeString(tempStartTime);
        trlNew->trl.startTime.wMinute = getMinuteFromMySQLTimeString(tempStartTime);
        trlNew->trl.startTime.wSecond = getSecondFromMySQLTimeString(tempStartTime);
        trlNew->trl.stopTime.wHour = getHourFromMySQLTimeString(tempStopTime);
        trlNew->trl.stopTime.wMinute = getMinuteFromMySQLTimeString(tempStopTime);
        trlNew->trl.stopTime.wSecond = getSecondFromMySQLTimeString(tempStopTime);
        if(trl==NULL)
        {
            trl = trlNew;
            sub = trl;
        }
        else
        {
            sub->next = trlNew;
            trlNew ->prev = sub;
            sub = sub->next;
        }
    }
    return trl;
}




int updateTRL(TimeRecordingLog trl)
{
    int error = 0;
    string50 tempStart,tempStop,tempInterruptionTime,tempDeltaTime;
    convertHourMinuteSecondToMySQLTime(tempStart,trl.startTime.wHour,trl.startTime.wMinute,trl.startTime.wSecond);
    convertHourMinuteSecondToMySQLTime(tempStop,trl.stopTime.wHour,trl.stopTime.wMinute,trl.stopTime.wSecond);
    convertFloatToString(tempInterruptionTime,trl.interruptonTime);
    convertFloatToString(tempDeltaTime,trl.deltaTime);
    string300 script = "update trl set trlStartDate = '";
    strcat(script,trl.startDate);
    strcat(script,"' , trlStopDate = '");
    strcat(script,trl.stopDate);
    strcat(script,"' , startTime = '");
    strcat(script,tempStart);
    strcat(script,"' , stopTime = '");
    strcat(script,tempStop);
    strcat(script,"' , interruptionTime = '");
    strcat(script,tempInterruptionTime);
    strcat(script,"' , deltaTime = '");
    strcat(script,tempDeltaTime);
    strcat(script,"' , phase = '");
    strcat(script,trl.phase);
    strcat(script,"' , comment = '");
    strcat(script,trl.comment);
    strcat(script,"'  where trlID = '");
    strcat(script,trl.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}



int addDRL(DefectRecordingLog drl)
{
    int error = 0;
    string50 tempFixTime;
    convertFloatToString(tempFixTime,drl.fixTime);
    string300 script = "insert into drl (projectID,drlDate,drlNumber,drlType,inject,remove,fixTime,fixDefect,description) values ('";
    strcat(script,drl.project.id);
    strcat(script,"','");
    strcat(script,drl.date);
    strcat(script,"','");
    strcat(script,drl.number);
    strcat(script,"','");
    strcat(script,drl.type);
    strcat(script,"','");
    strcat(script,drl.inject);
    strcat(script,"','");
    strcat(script,drl.remove);
    strcat(script,"','");
    strcat(script,tempFixTime);
    strcat(script,"','");
    strcat(script,drl.fixDefect);
    strcat(script,"','");
    strcat(script,drl.description);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}

DefectRecordingLogLinkedList getAllDRLBasedOnProject(DefectRecordingLogLinkedList drl, Project proj)
{
    DefectRecordingLogLinkedList drlNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "SELECT * FROM drl where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' order by drlNumber");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    drl = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        drlNew = malloc(sizeof(struct DefectRecordingLogLinked));
        drlNew->prev=NULL;
        drlNew->next=NULL;
        strcpy(drlNew->drl.id,row[0]);
        strcpy(drlNew->drl.project.id,row[1]);
        strcpy(drlNew->drl.date,row[2]);
        strcpy(drlNew->drl.number,row[3]);
        strcpy(drlNew->drl.type,row[4]);
        strcpy(drlNew->drl.inject,row[5]);
        strcpy(drlNew->drl.remove,row[6]);
        drlNew->drl.fixTime = convertStringToFloat(row[7]);
        strcpy(drlNew->drl.fixDefect,row[8]);
        strcpy(drlNew->drl.description,row[9]);
        if(drl==NULL)
        {
            drl = drlNew;
            sub = drl;
        }
        else
        {
            sub->next = drlNew;
            drlNew ->prev = sub;
            sub = sub->next;
        }
    }
    return drl;
}


int updateDRL(DefectRecordingLog drl)
{
    string50 tempFixTime;
    convertFloatToString(tempFixTime,drl.fixTime);
    int error = 0;
    string300 script = "update drl set drlNumber = '";
    strcat(script,drl.number);
    strcat(script,"' , drlType = '");
    strcat(script,drl.type);
    strcat(script,"' , inject = '");
    strcat(script,drl.inject);
    strcat(script,"' , remove = '");
    strcat(script,drl.remove);
    strcat(script,"' , fixTime = '");
    strcat(script,tempFixTime);
    strcat(script,"' , fixDefect = '");
    strcat(script,drl.fixDefect);
    strcat(script,"' , description = '");
    strcat(script,drl.description);
    strcat(script,"'  where drlID = '");
    strcat(script,drl.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}



int addTRT(TestReportTemplate trt)
{
    int error = 0;
    string300 script = "insert into trt (projectID,testName,testObjective,testDescription,testCondition,expectedResult,actualResult) values ('";
    strcat(script,trt.project.id);
    strcat(script,"','");
    strcat(script,trt.testName);
    strcat(script,"','");
    strcat(script,trt.testObjective);
    strcat(script,"','");
    strcat(script,trt.testDescription);
    strcat(script,"','");
    strcat(script,trt.testCondition);
    strcat(script,"','");
    strcat(script,trt.expectedResult);
    strcat(script,"','");
    strcat(script,trt.actualResult);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}


TestReportTemplateLinkedList getAllTRTBasedOnProject(TestReportTemplateLinkedList trt, Project proj)
{
    TestReportTemplateLinkedList trtNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "SELECT * FROM trt where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' order by trtID");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    trt = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        trtNew = malloc(sizeof(struct TestReportTemplateLinked));
        trtNew->prev=NULL;
        trtNew->next=NULL;
        strcpy(trtNew->trt.id,row[0]);
        strcpy(trtNew->trt.project.id,row[1]);
        strcpy(trtNew->trt.testName,row[2]);
        strcpy(trtNew->trt.testObjective,row[3]);
        strcpy(trtNew->trt.testDescription,row[4]);
        strcpy(trtNew->trt.testCondition,row[5]);
        strcpy(trtNew->trt.expectedResult,row[6]);
        strcpy(trtNew->trt.actualResult,row[7]);
        if(trt==NULL)
        {
            trt = trtNew;
            sub = trt;
        }
        else
        {
            sub->next = trtNew;
            trtNew ->prev = sub;
            sub = sub->next;
        }
    }
    return trt;
}



int updateTRT(TestReportTemplate trt)
{
    int error = 0;
    string300 script = "update trt set testName = '";
    strcat(script,trt.testName);
    strcat(script,"' , testObjective = '");
    strcat(script,trt.testObjective);
    strcat(script,"' , testDescription = '");
    strcat(script,trt.testDescription);
    strcat(script,"' , testCondition = '");
    strcat(script,trt.testCondition);
    strcat(script,"' , expectedResult = '");
    strcat(script,trt.expectedResult);
    strcat(script,"' , actualResult = '");
    strcat(script,trt.actualResult);
    strcat(script,"'  where trtID = '");
    strcat(script,trt.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




int addPIP(ProcessImprovementProposal pip)
{
    int error = 0;
    string300 script = "insert into pip (projectID,pipNumber,pipProblemDescription,pipProposalDescription,pipNotes) values ('";
    strcat(script,pip.project.id);
    strcat(script,"','");
    strcat(script,pip.pipNumber);
    strcat(script,"','");
    strcat(script,pip.pipProblemDescription);
    strcat(script,"','");
    strcat(script,pip.pipProposalDescription);
    strcat(script,"','");
    strcat(script,pip.pipNotes);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}


int addPIPNotes(char pipNotes[],char number[],Project proj)
{
    int error = 0;
    string300 script = "update pip set pipNotes = '";
    strcat(script,pipNotes);
    strcat(script,"'  where projectID = '");
    strcat(script,proj.id);
    strcat(script,"' and pipNumber = '");
    strcat(script,number);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}


ProcessImprovementProposalLinkedList getAllPIPBasedOnProject(ProcessImprovementProposalLinkedList pip, Project proj)
{
    ProcessImprovementProposalLinkedList pipNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "SELECT * FROM pip where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' order by pipNumber");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    pip = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        pipNew = malloc(sizeof(struct ProcessImprovementProposalLinked));
        pipNew->prev=NULL;
        pipNew->next=NULL;
        strcpy(pipNew->pip.id,row[0]);
        strcpy(pipNew->pip.project.id,row[1]);
        strcpy(pipNew->pip.pipNumber,row[2]);
        strcpy(pipNew->pip.pipProblemDescription,row[3]);
        strcpy(pipNew->pip.pipProposalDescription,row[4]);
        strcpy(pipNew->pip.pipNotes,row[5]);
        if(pip==NULL)
        {
            pip = pipNew;
            sub = pip;
        }
        else
        {
            sub->next = pipNew;
            pipNew ->prev = sub;
            sub = sub->next;
        }
    }
    return pip;
}




int updatePIP(ProcessImprovementProposal pip)
{
    int error = 0;
    string300 script = "update pip set pipNumber = '";
    strcat(script,pip.pipNumber);
    strcat(script,"' , pipProblemDescription = '");
    strcat(script,pip.pipProblemDescription);
    strcat(script,"' , pipProposalDescription = '");
    strcat(script,pip.pipProposalDescription);
    strcat(script,"'  where pipID = '");
    strcat(script,pip.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}



int addTPT(TaskPlanningTemplate tpt)
{
    string50 planMinutes,planValue,planCumulativeMinutes,planCumulativeValue;
    string50 actualValue,actualCumulativeValue;
    string50 realActualValue,realActualCumulativeValue;
    //Planned
    convertFloatToString(planMinutes,tpt.planMinutes);
    convertFloatToString(planValue,tpt.planValue);
    convertFloatToString(planCumulativeMinutes,tpt.planCumulativeMinutes);
    convertFloatToString(planCumulativeValue,tpt.planCumulativeValue);

    //Actual
    convertFloatToString(actualValue,tpt.actualValue);
    convertFloatToString(actualCumulativeValue,tpt.actualCumulativeValue);

    //Real Actual
    convertFloatToString(realActualValue,tpt.realActualValue);
    convertFloatToString(realActualCumulativeValue,tpt.realActualCumulativeValue);

    int error = 0;
    string1000 script = "insert into tpt (projectID,taskName,planMinutes,planValue,planCumulativeMinutes,planCumulativeValue,planDate,actualDate,actualValue,actualCumulativeValue,realActualValue,realActualCumulativeValue) values ('";
    strcat(script,tpt.project.id);
    strcat(script,"','");
    strcat(script,tpt.taskName);
    strcat(script,"','");
    strcat(script,planMinutes);
    strcat(script,"','");
    strcat(script,planValue);
    strcat(script,"','");
    strcat(script,planCumulativeMinutes);
    strcat(script,"','");
    strcat(script,planCumulativeValue);
    strcat(script,"','");
    strcat(script,tpt.planDate);
    strcat(script,"','");
    strcat(script,tpt.actualDate);
    strcat(script,"','");
    strcat(script,actualValue);
    strcat(script,"','");
    strcat(script,actualCumulativeValue);
    strcat(script,"','");
    strcat(script,realActualValue);
    strcat(script,"','");
    strcat(script,realActualCumulativeValue);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




TaskPlanningTemplateLinkedList getAllTPTBasedOnProject(TaskPlanningTemplateLinkedList tpt, Project proj)
{
    TaskPlanningTemplateLinkedList tptNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string300 script = "SELECT * FROM tpt where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' order by tptID");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    tpt = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        tptNew = malloc(sizeof(struct TaskPlanningTemplateLinked));
        tptNew->prev=NULL;
        tptNew->next=NULL;
        strcpy(tptNew->tpt.id,row[0]);
        strcpy(tptNew->tpt.project.id,row[1]);
        strcpy(tptNew->tpt.taskName,row[2]);
        tptNew->tpt.planMinutes = convertStringToFloat(row[3]);
        tptNew->tpt.planValue = convertStringToFloat(row[4]);
        tptNew->tpt.planCumulativeMinutes = convertStringToFloat(row[5]);
        tptNew->tpt.planCumulativeValue = convertStringToFloat(row[6]);
        strcpy(tptNew->tpt.planDate,row[7]);
        strcpy(tptNew->tpt.actualDate,row[8]);
        tptNew->tpt.actualValue = convertStringToFloat(row[9]);
        tptNew->tpt.actualCumulativeValue = convertStringToFloat(row[10]);
        tptNew->tpt.realActualValue = convertStringToFloat(row[11]);
        tptNew->tpt.realActualCumulativeValue = convertStringToFloat(row[12]);
        if(tpt==NULL)
        {
            tpt = tptNew;
            sub = tpt;
        }
        else
        {
            sub->next = tptNew;
            tptNew ->prev = sub;
            sub = sub->next;
        }
    }
    return tpt;
}




TaskPlanningTemplateLinkedList getTPTBasedOnPhaseAndProject(TaskPlanningTemplateLinkedList tpt, Project proj,char phase[])
{
    int error = 0;
    TaskPlanningTemplateLinkedList tptNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string1000 script = "SELECT * FROM tpt where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' and taskName = '");
    strcat(script,phase);
    strcat(script,"' order by tptID");
    error = mysql_query(conn, script); //execute the script
    if(error)
    {
        return NULL;
    }
    rs = mysql_use_result(conn); // grab the result
    tpt = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        tptNew = malloc(sizeof(struct TaskPlanningTemplateLinked));
        tptNew->prev=NULL;
        tptNew->next=NULL;
        strcpy(tptNew->tpt.id,row[0]);
        strcpy(tptNew->tpt.project.id,row[1]);
        strcpy(tptNew->tpt.taskName,row[2]);
        tptNew->tpt.planMinutes = convertStringToFloat(row[3]);
        tptNew->tpt.planValue = convertStringToFloat(row[4]);
        tptNew->tpt.planCumulativeMinutes = convertStringToFloat(row[5]);
        tptNew->tpt.planCumulativeValue = convertStringToFloat(row[6]);
        strcpy(tptNew->tpt.planDate,row[7]);
        strcpy(tptNew->tpt.actualDate,row[8]);
        tptNew->tpt.actualValue = convertStringToFloat(row[9]);
        tptNew->tpt.actualCumulativeValue = convertStringToFloat(row[10]);
        tptNew->tpt.realActualValue = convertStringToFloat(row[11]);
        tptNew->tpt.realActualCumulativeValue = convertStringToFloat(row[12]);
        if(tpt==NULL)
        {
            tpt = tptNew;
            sub = tpt;
        }
        else
        {
            sub->next = tptNew;
            tptNew ->prev = sub;
            sub = sub->next;
        }
    }
    return tpt;
}



int deleteTPTBasedOnProject(Project project)
{
    int error = 0;
    string1000 script = "delete from tpt where projectID='";
    strcat(script,project.id);
    strcat(script,"' ");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}



boolean isTPTDatabaseEmpty(Project proj)
{
    TaskPlanningTemplateLinkedList tpt = NULL;
    tpt = getAllTPTBasedOnProject(tpt,proj);
    if(tpt!=NULL)
    {
        return FALSE;
    }
    return TRUE;
}


int updateTPT(TaskPlanningTemplate tpt)
{
    string10 planMinutes,planValue,planCumulativeMinutes,planCumulativeValue;
    string10 actualValue,actualCumulativeValue;
    string10 realActualValue,realActualCumulativeValue;
    //Planned
    convertFloatToString(planMinutes,tpt.planMinutes);
    convertFloatToString(planValue,tpt.planValue);
    convertFloatToString(planCumulativeMinutes,tpt.planCumulativeMinutes);
    convertFloatToString(planCumulativeValue,tpt.planCumulativeValue);

    //Actual
    convertFloatToString(actualValue,tpt.actualValue);
    convertFloatToString(actualCumulativeValue,tpt.actualCumulativeValue);

    //Real Actual
    convertFloatToString(realActualValue,tpt.realActualValue);
    convertFloatToString(realActualCumulativeValue,tpt.realActualCumulativeValue);

    int error = 0;
    string1000 script = "update tpt set taskName = '";
    strcat(script,tpt.taskName);
    strcat(script,"' , planMinutes = '");
    strcat(script,planMinutes);
    strcat(script,"' , planValue = '");
    strcat(script,planValue);
    strcat(script,"' , planCumulativeMinutes = '");
    strcat(script,planCumulativeMinutes);
    strcat(script,"' , planCumulativeValue = '");
    strcat(script,planCumulativeValue);
    strcat(script,"' , planDate = '");
    strcat(script,tpt.planDate);
    strcat(script,"' , actualDate = '");
    strcat(script,tpt.actualDate);
    strcat(script,"' , actualValue = '");
    strcat(script,actualValue);
    strcat(script,"' , actualCumulativeValue = '");
    strcat(script,actualCumulativeValue);
    strcat(script,"' , realActualValue = '");
    strcat(script,realActualValue);
    strcat(script,"' , realActualCumulativeValue = '");
    strcat(script,realActualCumulativeValue);
    strcat(script,"'  where tptID = '");
    strcat(script,tpt.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




int addSPT(SchedulePlanningTemplate spt)
{
    string50 planMinutes,planCumulativeMinutes,planCumulativeValue;
    string50 actualMinutes,actualCumulativeMinutes,actualCumulativeValue;
    string50 adjustedEarnedValue;

    //Planned
    convertFloatToString(planMinutes,spt.planMinutes);
    convertFloatToString(planCumulativeMinutes,spt.planCumulativeMinutes);
    convertFloatToString(planCumulativeValue,spt.planCumulativeValue);

    //Actual
    convertFloatToString(actualMinutes,spt.actualMinutes);
    convertFloatToString(actualCumulativeMinutes,spt.actualCumulativeMinutes);
    convertFloatToString(actualCumulativeValue,spt.actualCumulativeValue);

    //Adjusted Earned Value
    convertFloatToString(adjustedEarnedValue,spt.adjustedEarnedValue);

    int error = 0;
    string1000 script = "insert into spt (projectID,dayNumber,sptPlanDate,sptPlanMinutes,sptPlanCumulativeMinutes,sptPlanCumulativeValue,sptActualMinutes,sptActualCumulativeMinutes,sptActualCumulativeValue,sptAdjustedEarnedValue) values ('";
    strcat(script,spt.project.id);
    strcat(script,"','");
    strcat(script,spt.dayNumber);
    strcat(script,"','");
    strcat(script,spt.planDate);
    strcat(script,"','");
    strcat(script,planMinutes);
    strcat(script,"','");
    strcat(script,planCumulativeMinutes);
    strcat(script,"','");
    strcat(script,planCumulativeValue);
    strcat(script,"','");
    strcat(script,actualMinutes);
    strcat(script,"','");
    strcat(script,actualCumulativeMinutes);
    strcat(script,"','");
    strcat(script,actualCumulativeValue);
    strcat(script,"','");
    strcat(script,adjustedEarnedValue);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}



SchedulePlanningTemplateLinkedList getAllSPTBasedOnProject(SchedulePlanningTemplateLinkedList spt, Project proj)
{
    SchedulePlanningTemplateLinkedList sptNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string1000 script = "SELECT * FROM spt where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' order by dayNumber");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    spt = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        sptNew = malloc(sizeof(struct SchedulePlanningTemplateLinked));
        sptNew->prev=NULL;
        sptNew->next=NULL;
        strcpy(sptNew->spt.id,row[0]);
        strcpy(sptNew->spt.project.id,row[1]);
        strcpy(sptNew->spt.dayNumber,row[2]);
        strcpy(sptNew->spt.planDate,row[3]);
        sptNew->spt.planMinutes = convertStringToFloat(row[4]);
        sptNew->spt.planCumulativeMinutes = convertStringToFloat(row[5]);
        sptNew->spt.planCumulativeValue = convertStringToFloat(row[6]);
        sptNew->spt.actualMinutes = convertStringToFloat(row[7]);
        sptNew->spt.actualCumulativeMinutes = convertStringToFloat(row[8]);
        sptNew->spt.actualCumulativeValue = convertStringToFloat(row[9]);
        sptNew->spt.adjustedEarnedValue = convertStringToFloat(row[10]);
        if(spt==NULL)
        {
            spt = sptNew;
            sub = spt;
        }
        else
        {
            sub->next = sptNew;
            sptNew ->prev = sub;
            sub = sub->next;
        }
    }
    return spt;
}




boolean isSPTDatabaseEmpty(Project proj)
{
    SchedulePlanningTemplateLinkedList spt = NULL;
    spt = getAllSPTBasedOnProject(spt,proj);
    if(spt!=NULL)
    {
        return FALSE;
    }
    return TRUE;
}




int updateSPT(SchedulePlanningTemplate spt)
{
    string50 planMinutes,planCumulativeMinutes,planCumulativeValue;
    string50 actualMinutes,actualCumulativeMinutes,actualCumulativeValue;
    string50 adjustedEarnedValue;

    //Planned
    convertFloatToString(planMinutes,spt.planMinutes);
    convertFloatToString(planCumulativeMinutes,spt.planCumulativeMinutes);
    convertFloatToString(planCumulativeValue,spt.planCumulativeValue);

    //Actual
    convertFloatToString(actualMinutes,spt.actualMinutes);
    convertFloatToString(actualCumulativeMinutes,spt.actualCumulativeMinutes);
    convertFloatToString(actualCumulativeValue,spt.actualCumulativeValue);

    //Adjusted Earned Value
    convertFloatToString(adjustedEarnedValue,spt.adjustedEarnedValue);

    int error = 0;
    string1000 script = "update spt set dayNumber = '";
    strcat(script,spt.dayNumber);
    strcat(script,"' , sptPlanDate = '");
    strcat(script,spt.planDate);
    strcat(script,"' , sptPlanMinutes = '");
    strcat(script,planMinutes);
    strcat(script,"' , sptPlanCumulativeMinutes = '");
    strcat(script,planCumulativeMinutes);
    strcat(script,"' , sptPlanCumulativeValue = '");
    strcat(script,planCumulativeValue);
    strcat(script,"' , sptActualMinutes = '");
    strcat(script,actualMinutes);
    strcat(script,"' , sptActualCumulativeMinutes = '");
    strcat(script,actualCumulativeMinutes);
    strcat(script,"' , sptActualCumulativeValue = '");
    strcat(script,actualCumulativeValue);
    strcat(script,"' , sptAdjustedEarnedValue = '");
    strcat(script,adjustedEarnedValue);
    strcat(script,"'  where sptID = '");
    strcat(script,spt.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}





int addSET(SizeEstimatingTemplate set)
{
    string50 baseProgamBaseSize;
    string50 baseProgramLOCDeleted;
    string50 baseProgramLOCModified;

    string50 projectedLOC;
    string50 b0;
    string50 b1;

    string50 estimatedNewAndChangedLOC;
    string50 estimatedTotalLOC;
    string50 estimatedTotalNewReused;

    string50 predictionRange;
    string50 upperPredictionInterval;
    string50 lowerPredictionInterval;
    string50 predictionIntervalPercent;

    //Base Program
    convertFloatToString(baseProgamBaseSize,set.baseProgamBaseSize);
    convertFloatToString(baseProgramLOCDeleted,set.baseProgramLOCDeleted);
    convertFloatToString(baseProgramLOCModified,set.baseProgramLOCModified);

    convertFloatToString(projectedLOC,set.projectedLOC);
    convertFloatToString(b0,set.b0);
    convertFloatToString(b1,set.b1);

    //Estimated
    convertFloatToString(estimatedNewAndChangedLOC,set.estimatedNewAndChangedLOC);
    convertFloatToString(estimatedTotalLOC,set.estimatedTotalLOC);
    convertFloatToString(estimatedTotalNewReused,set.estimatedTotalNewReused);


    convertFloatToString(predictionRange,set.predictionRange);
    convertFloatToString(upperPredictionInterval,set.upperPredictionInterval);
    convertFloatToString(lowerPredictionInterval,set.lowerPredictionInterval);
    convertFloatToString(predictionIntervalPercent,set.predictionIntervalPercent);

    int error = 0;
    string1000 script = "insert into sizeestimatingtemplate (projectID,baseProgramBaseSize,baseProgramLOCDeleted,baseProgramLOCModified,projectedLOC,b0,b1,estimatedNewAndChangedLOC,estimatedTotalLOC,estimatedTotalNewReused,predictionRange,upperPredictionInterval,lowerPredictionInterval,predictionIntervalPercent,setType) values ('";
    strcat(script,set.project.id);
    strcat(script,"','");
    strcat(script,baseProgamBaseSize);
    strcat(script,"','");
    strcat(script,baseProgramLOCDeleted);
    strcat(script,"','");
    strcat(script,baseProgramLOCModified);
    strcat(script,"','");
    strcat(script,projectedLOC);
    strcat(script,"','");
    strcat(script,b0);
    strcat(script,"','");
    strcat(script,b1);
    strcat(script,"','");
    strcat(script,estimatedNewAndChangedLOC);
    strcat(script,"','");
    strcat(script,estimatedTotalLOC);
    strcat(script,"','");
    strcat(script,estimatedTotalNewReused);
    strcat(script,"','");
    strcat(script,predictionRange);
    strcat(script,"','");
    strcat(script,upperPredictionInterval);
    strcat(script,"','");
    strcat(script,lowerPredictionInterval);
    strcat(script,"','");
    strcat(script,predictionIntervalPercent);
    strcat(script,"','");
    strcat(script,set.setType);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




SizeEstimatingTemplateLinkedList getAllSETBasedOnProjectAndType(SizeEstimatingTemplateLinkedList set, Project proj,char setType[])
{
    SizeEstimatingTemplateLinkedList setNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string1000 script = "SELECT * FROM sizeestimatingtemplate where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' and setType = '");
    strcat(script,setType);
    strcat(script,"' order by setID desc");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    set = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        setNew = malloc(sizeof(struct SizeEstimatingTemplateLinked));
        setNew->prev=NULL;
        setNew->next=NULL;
        strcpy(setNew->set.id,row[0]);
        strcpy(setNew->set.project.id,row[1]);
        setNew->set.baseProgamBaseSize = convertStringToFloat(row[2]);
        setNew->set.baseProgramLOCDeleted = convertStringToFloat(row[3]);
        setNew->set.baseProgramLOCModified = convertStringToFloat(row[4]);

        setNew->set.projectedLOC = convertStringToFloat(row[5]);
        setNew->set.b0 = convertStringToFloat(row[6]);
        setNew->set.b1 = convertStringToFloat(row[7]);

        setNew->set.estimatedNewAndChangedLOC = convertStringToFloat(row[8]);
        setNew->set.estimatedTotalLOC = convertStringToFloat(row[9]);
        setNew->set.estimatedTotalNewReused = convertStringToFloat(row[10]);

        setNew->set.predictionRange = convertStringToFloat(row[11]);
        setNew->set.upperPredictionInterval = convertStringToFloat(row[12]);
        setNew->set.lowerPredictionInterval = convertStringToFloat(row[13]);
        setNew->set.predictionIntervalPercent = convertStringToFloat(row[14]);

        strcpy(setNew->set.setType,row[15]);

        if(set==NULL)
        {
            set = setNew;
            sub = set;
        }
        else
        {
            sub->next = setNew;
            setNew ->prev = sub;
            sub = sub->next;
        }
    }
    return set;
}






int updateSET(SizeEstimatingTemplate set)
{
    string50 baseProgamBaseSize;
    string50 baseProgramLOCDeleted;
    string50 baseProgramLOCModified;

    string50 projectedLOC;
    string50 b0;
    string50 b1;

    string50 estimatedNewAndChangedLOC;
    string50 estimatedTotalLOC;
    string50 estimatedTotalNewReused;

    string50 predictionRange;
    string50 upperPredictionInterval;
    string50 lowerPredictionInterval;
    string50 predictionIntervalPercent;

    //Base Program
    convertFloatToString(baseProgamBaseSize,set.baseProgamBaseSize);
    convertFloatToString(baseProgramLOCDeleted,set.baseProgramLOCDeleted);
    convertFloatToString(baseProgramLOCModified,set.baseProgramLOCModified);

    convertFloatToString(projectedLOC,set.projectedLOC);
    convertFloatToString(b0,set.b0);
    convertFloatToString(b1,set.b1);

    //Estimated
    convertFloatToString(estimatedNewAndChangedLOC,set.estimatedNewAndChangedLOC);
    convertFloatToString(estimatedTotalLOC,set.estimatedTotalLOC);
    convertFloatToString(estimatedTotalNewReused,set.estimatedTotalNewReused);


    convertFloatToString(predictionRange,set.predictionRange);
    convertFloatToString(upperPredictionInterval,set.upperPredictionInterval);
    convertFloatToString(lowerPredictionInterval,set.lowerPredictionInterval);
    convertFloatToString(predictionIntervalPercent,set.predictionIntervalPercent);

    int error = 0;
    string1000 script = "update sizeestimatingtemplate set baseProgramBaseSize = '";
    strcat(script,baseProgamBaseSize);
    strcat(script,"' , baseProgramLOCDeleted = '");
    strcat(script,baseProgramLOCDeleted);
    strcat(script,"' , baseProgramLOCModified = '");
    strcat(script,baseProgramLOCModified);
    strcat(script,"' , projectedLOC = '");
    strcat(script,projectedLOC);
    strcat(script,"' , b0 = '");
    strcat(script,b0);
    strcat(script,"' , b1 = '");
    strcat(script,b1);
    strcat(script,"' , estimatedNewAndChangedLOC = '");
    strcat(script,estimatedNewAndChangedLOC);
    strcat(script,"' , estimatedTotalLOC = '");
    strcat(script,estimatedTotalLOC);
    strcat(script,"' , estimatedTotalNewReused = '");
    strcat(script,estimatedTotalNewReused);
    strcat(script,"' , predictionRange = '");
    strcat(script,predictionRange);
    strcat(script,"' , upperPredictionInterval = '");
    strcat(script,upperPredictionInterval);
    strcat(script,"' , lowerPredictionInterval = '");
    strcat(script,lowerPredictionInterval);
    strcat(script,"' , predictionIntervalPercent = '");
    strcat(script,predictionIntervalPercent);
    strcat(script,"'  where setID = '");
    strcat(script,set.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




int addSETProjectedLOC(SETProjectedLOC setProjectedLOC)
{
    string50 setProjectedLOCLOC;

    convertFloatToString(setProjectedLOCLOC,setProjectedLOC.setProjectedLOCLOC);

    int error = 0;
    string1000 script = "insert into setprojectedloc (setID,setProjectedLOCName,setProjectedLOCType,setProjectedLOCMethod,setProjectedLOCSize,setProjectedLOCLOC,typeOfProjectedLOC) values ('";
    strcat(script,setProjectedLOC.set.id);
    strcat(script,"','");
    strcat(script,setProjectedLOC.setProjectedLOCName);
    strcat(script,"','");
    strcat(script,setProjectedLOC.setProjectedLOCType);
    strcat(script,"','");
    strcat(script,setProjectedLOC.setProjectedLOCMethod);
    strcat(script,"','");
    strcat(script,setProjectedLOC.setProjectedLOCSize);
    strcat(script,"','");
    strcat(script,setProjectedLOCLOC);
    strcat(script,"','");
    strcat(script,setProjectedLOC.typeOfProjectedLOC);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




SETProjectedLOCLinkedList getAllSETProjectedLOCBasedOnSETAndTypeOfProjectedLOC(SETProjectedLOCLinkedList setProjectedLOC, SizeEstimatingTemplate set, char typeOfProjectedLOC[])
{
    SETProjectedLOCLinkedList setProjectedLOCNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string1000 script = "select * from setprojectedloc where setID = '";
    strcat(script,set.id);
    strcat(script,"' and typeOfProjectedLOC = '");
    strcat(script,typeOfProjectedLOC);
    strcat(script,"' order by setProjectedLOCName");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    setProjectedLOC = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        setProjectedLOCNew = malloc(sizeof(struct SETProjectedLOCLinked));
        setProjectedLOCNew->prev=NULL;
        setProjectedLOCNew->next=NULL;
        strcpy(setProjectedLOCNew->setProjectedLOC.id,row[0]);
        strcpy(setProjectedLOCNew->setProjectedLOC.set.id,row[1]);
        strcpy(setProjectedLOCNew->setProjectedLOC.setProjectedLOCName,row[2]);
        strcpy(setProjectedLOCNew->setProjectedLOC.setProjectedLOCType,row[3]);
        strcpy(setProjectedLOCNew->setProjectedLOC.setProjectedLOCMethod,row[4]);
        strcpy(setProjectedLOCNew->setProjectedLOC.setProjectedLOCSize,row[5]);
        setProjectedLOCNew->setProjectedLOC.setProjectedLOCLOC = convertStringToFloat(row[6]);
        strcpy(setProjectedLOCNew->setProjectedLOC.typeOfProjectedLOC,row[7]);

        if(setProjectedLOC==NULL)
        {
            setProjectedLOC = setProjectedLOCNew;
            sub = setProjectedLOC;
        }
        else
        {
            sub->next = setProjectedLOCNew;
            setProjectedLOCNew ->prev = sub;
            sub = sub->next;
        }
    }
    return setProjectedLOC;
}





int updateSETProjectedLOC(SETProjectedLOC setProjectedLOC)
{
    string50 setProjectedLOCLOC;

    convertFloatToString(setProjectedLOCLOC,setProjectedLOC.setProjectedLOCLOC);

    int error = 0;
    string1000 script = "update setprojectedloc set setProjectedLOCName = '";
    strcat(script,setProjectedLOC.setProjectedLOCName);
    strcat(script,"' , setProjectedLOCType = '");
    strcat(script,setProjectedLOC.setProjectedLOCType);
    strcat(script,"' , setProjectedLOCMethod = '");
    strcat(script,setProjectedLOC.setProjectedLOCMethod);
    strcat(script,"' , setProjectedLOCSize = '");
    strcat(script,setProjectedLOC.setProjectedLOCSize);
    strcat(script,"' , setProjectedLOCLOC = '");
    strcat(script,setProjectedLOCLOC);
    strcat(script,"' , typeOfProjectedLOC = '");
    strcat(script,setProjectedLOC.typeOfProjectedLOC);
    strcat(script,"'  where setProjectedLOCID = '");
    strcat(script,setProjectedLOC.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}





int addSETReusedFunction(SETReusedFunction setReusedFunction)
{
    string50 reusedFunctionLOC;

    convertFloatToString(reusedFunctionLOC,setReusedFunction.reusedFunctionLOC);

    int error = 0;
    string1000 script = "insert into setreusedfunction (setID,reusedFunctionName,reusedFunctionLOC) values ('";
    strcat(script,setReusedFunction.set.id);
    strcat(script,"','");
    strcat(script,setReusedFunction.reusedFunctionName);
    strcat(script,"','");
    strcat(script,reusedFunctionLOC);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




SETReusedFunctionLinkedList getAllSETReusedFunctionBasedOnSET(SETReusedFunctionLinkedList setReusedFunction, SizeEstimatingTemplate set)
{
    SETReusedFunctionLinkedList setReusedFunctionNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string1000 script = "select * from setreusedfunction where setID = '";
    strcat(script,set.id);
    strcat(script,"' order by reusedFunctionName");
    mysql_query(conn, script); //execute the script
    rs = mysql_use_result(conn); // grab the result
    setReusedFunction = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        setReusedFunctionNew = malloc(sizeof(struct SETReusedFunctionLinked));
        setReusedFunctionNew->prev=NULL;
        setReusedFunctionNew->next=NULL;
        strcpy(setReusedFunctionNew->setReusedFunction.id,row[0]);
        strcpy(setReusedFunctionNew->setReusedFunction.set.id,row[1]);
        strcpy(setReusedFunctionNew->setReusedFunction.reusedFunctionName,row[2]);
        setReusedFunctionNew->setReusedFunction.reusedFunctionLOC = convertStringToFloat(row[3]);

        if(setReusedFunction==NULL)
        {
            setReusedFunction = setReusedFunctionNew;
            sub = setReusedFunction;
        }
        else
        {
            sub->next = setReusedFunctionNew;
            setReusedFunctionNew ->prev = sub;
            sub = sub->next;
        }
    }
    return setReusedFunction;
}




int updateSETReusedFunction(SETReusedFunction setReusedFunction)
{
    string50 reusedFunctionLOC;

    convertFloatToString(reusedFunctionLOC,setReusedFunction.reusedFunctionLOC);

    int error = 0;
    string1000 script = "update setreusedfunction set reusedFunctionName = '";
    strcat(script,setReusedFunction.reusedFunctionName);
    strcat(script,"' , reusedFunctionLOC = '");
    strcat(script,reusedFunctionLOC);
    strcat(script,"'  where setReusedFunctionID = '");
    strcat(script,setReusedFunction.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}




boolean isALLSizeEstimatingTemplateDatabaseEmpty(Project proj)
{
    SizeEstimatingTemplateLinkedList set = NULL;
    SETProjectedLOCLinkedList setProjectedLOC = NULL;
    set = getAllSETBasedOnProjectAndType(set,proj,SET_TYPE_PLAN);
    if(set!=NULL)
    {
        setProjectedLOC = getAllSETProjectedLOCBasedOnSETAndTypeOfProjectedLOC(setProjectedLOC,set->set,TYPE_OF_PROJECTEC_LOC_NF);
        if(setProjectedLOC!=NULL)
        {
            return FALSE;
        }
    }
    return TRUE;
}





int addPPS(ProjectPlanSummary pps)
{
    string25 summaryLOCPerHour;
    string25 summaryPlanTime;
    string25 summaryActualTime;
    string25 summaryCPI;
    string25 summaryPercentReused;
    string25 summaryPercentNewReused;

    string25 programSizeBase;
    string25 programSizeDeleted;
    string25 programSizeModified;
    string25 programSizeAdded;
    string25 programSizeReused;
    string25 programSizeNewAndChanged;
    string25 programSizeTotalLOC;
    string25 programSizeNewReused;

    string25 trlPlanning;
    string25 trlDesign;
    string25 trlCode;
    string25 trlCompile;
    string25 trlTest;
    string25 trlPostmortem;

    string25 injectPlanning;
    string25 injectDesign;
    string25 injectCode;
    string25 injectCompile;
    string25 injectTest;


    string25 removePlanning;
    string25 removeDesign;
    string25 removeCode;
    string25 removeCompile;
    string25 removeTest;
    string25 removeAfterDevelopment;

    convertFloatToString(summaryLOCPerHour,pps.summaryLOCPerHour);
    convertFloatToString(summaryPlanTime,pps.summaryPlanTime);
    convertFloatToString(summaryActualTime,pps.summaryActualTime);
    convertFloatToString(summaryCPI,pps.summaryCPI);
    convertFloatToString(summaryPercentReused,pps.summaryPercentReused);
    convertFloatToString(summaryPercentNewReused,pps.summaryPercentNewReused);


    convertFloatToString(programSizeBase,pps.programSizeBase);
    convertFloatToString(programSizeDeleted,pps.programSizeDeleted);
    convertFloatToString(programSizeModified,pps.programSizeModified);
    convertFloatToString(programSizeAdded,pps.programSizeAdded);
    convertFloatToString(programSizeReused,pps.programSizeReused);
    convertFloatToString(programSizeNewAndChanged,pps.programSizeNewAndChanged);
    convertFloatToString(programSizeTotalLOC,pps.programSizeTotalLOC);
    convertFloatToString(programSizeNewReused,pps.programSizeNewReused);


    convertFloatToString(trlPlanning,pps.trlPlanning);
    convertFloatToString(trlDesign,pps.trlDesign);
    convertFloatToString(trlCode,pps.trlCode);
    convertFloatToString(trlCompile,pps.trlCompile);
    convertFloatToString(trlTest,pps.trlTest);
    convertFloatToString(trlPostmortem,pps.trlPostmortem);


    convertFloatToString(injectPlanning,pps.injectPlanning);
    convertFloatToString(injectDesign,pps.injectDesign);
    convertFloatToString(injectCode,pps.injectCode);
    convertFloatToString(injectCompile,pps.injectCompile);
    convertFloatToString(injectTest,pps.injectTest);


    convertFloatToString(removePlanning,pps.removePlanning);
    convertFloatToString(removeDesign,pps.removeDesign);
    convertFloatToString(removeCode,pps.removeCode);
    convertFloatToString(removeCompile,pps.removeCompile);
    convertFloatToString(removeTest,pps.removeTest);
    convertFloatToString(removeAfterDevelopment,pps.removeAfterDevelopment);


    int error = 0;
    string1000 script = "insert into pps (projectID,summaryLOCPerHour,summaryPlanTime,summaryActualTime,summaryCPI,summaryPercentReused,summaryPercentNewReused,programSizeBase,programSizeDeleted,programSizeModified,programSizeAdded,programSizeReused,programSizeNewAndChanged,programSizeTotalLOC,programSizeNewReused,trlPlanning,trlDesign,trlCode,trlCompile,trlTest,trlPostmortem,injectPlanning,injectDesign,injectCode,injectCompile,injectTest,removePlanning,removeDesign,removeCode,removeCompile,removeTest,removeAfterDevelopment,ppsType) values ('";
    strcat(script,pps.project.id);
    strcat(script,"','");

    strcat(script,summaryLOCPerHour);
    strcat(script,"','");
    strcat(script,summaryPlanTime);
    strcat(script,"','");
    strcat(script,summaryActualTime);
    strcat(script,"','");
    strcat(script,summaryCPI);
    strcat(script,"','");
    strcat(script,summaryPercentReused);
    strcat(script,"','");
    strcat(script,summaryPercentNewReused);
    strcat(script,"','");


    strcat(script,programSizeBase);
    strcat(script,"','");
    strcat(script,programSizeDeleted);
    strcat(script,"','");
    strcat(script,programSizeModified);
    strcat(script,"','");
    strcat(script,programSizeAdded);
    strcat(script,"','");
    strcat(script,programSizeReused);
    strcat(script,"','");
    strcat(script,programSizeNewAndChanged);
    strcat(script,"','");
    strcat(script,programSizeTotalLOC);
    strcat(script,"','");
    strcat(script,programSizeNewReused);
    strcat(script,"','");


    strcat(script,trlPlanning);
    strcat(script,"','");
    strcat(script,trlDesign);
    strcat(script,"','");
    strcat(script,trlCode);
    strcat(script,"','");
    strcat(script,trlCompile);
    strcat(script,"','");
    strcat(script,trlTest);
    strcat(script,"','");
    strcat(script,trlPostmortem);
    strcat(script,"','");


    strcat(script,injectPlanning);
    strcat(script,"','");
    strcat(script,injectDesign);
    strcat(script,"','");
    strcat(script,injectCode);
    strcat(script,"','");
    strcat(script,injectCompile);
    strcat(script,"','");
    strcat(script,injectTest);
    strcat(script,"','");


    strcat(script,removePlanning);
    strcat(script,"','");
    strcat(script,removeDesign);
    strcat(script,"','");
    strcat(script,removeCode);
    strcat(script,"','");
    strcat(script,removeCompile);
    strcat(script,"','");
    strcat(script,removeTest);
    strcat(script,"','");
    strcat(script,removeAfterDevelopment);
    strcat(script,"','");

    strcat(script,pps.ppsType);
    strcat(script,"')");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}





ProjectPlanSummaryLinkedList getAllPPSBasedOnProjectAndPPSType(ProjectPlanSummaryLinkedList pps, Project proj,char ppsType[])
{
    ProjectPlanSummaryLinkedList ppsNew,sub;
    MYSQL_RES *rs; /* holds the result set */
    MYSQL_ROW row;
    string1000 script = "SELECT * FROM pps where projectID = '";
    strcat(script,proj.id);
    strcat(script,"' and ppsType = '");
    strcat(script,ppsType);
    strcat(script,"' order by ppsID");
    if(mysql_query(conn, script)) //execute the script
    {
        showMySQLDatabaseError();
    }
    rs = mysql_use_result(conn); // grab the result
    pps = NULL;
    while((row = mysql_fetch_row(rs)) != NULL) //get each row
    {
        ppsNew = malloc(sizeof(struct ProjectPlanSummaryLinked));
        ppsNew->prev=NULL;
        ppsNew->next=NULL;
        strcpy(ppsNew->pps.id,row[0]);
        strcpy(ppsNew->pps.project.id,row[1]);
        ppsNew->pps.summaryLOCPerHour = convertStringToFloat(row[2]);
        ppsNew->pps.summaryPlanTime = convertStringToFloat(row[3]);
        ppsNew->pps.summaryActualTime = convertStringToFloat(row[4]);
        ppsNew->pps.summaryCPI = convertStringToFloat(row[5]);
        ppsNew->pps.summaryPercentReused = convertStringToFloat(row[6]);
        ppsNew->pps.summaryPercentNewReused = convertStringToFloat(row[7]);

        ppsNew->pps.programSizeBase = convertStringToFloat(row[8]);
        ppsNew->pps.programSizeDeleted = convertStringToFloat(row[9]);
        ppsNew->pps.programSizeModified = convertStringToFloat(row[10]);
        ppsNew->pps.programSizeAdded = convertStringToFloat(row[11]);
        ppsNew->pps.programSizeReused = convertStringToFloat(row[12]);
        ppsNew->pps.programSizeNewAndChanged = convertStringToFloat(row[13]);
        ppsNew->pps.programSizeTotalLOC = convertStringToFloat(row[14]);
        ppsNew->pps.programSizeNewReused = convertStringToFloat(row[15]);

        ppsNew->pps.trlPlanning = convertStringToFloat(row[16]);
        ppsNew->pps.trlDesign = convertStringToFloat(row[17]);
        ppsNew->pps.trlCode = convertStringToFloat(row[18]);
        ppsNew->pps.trlCompile = convertStringToFloat(row[19]);
        ppsNew->pps.trlTest = convertStringToFloat(row[20]);
        ppsNew->pps.trlPostmortem = convertStringToFloat(row[21]);

        ppsNew->pps.injectPlanning = convertStringToFloat(row[22]);
        ppsNew->pps.injectDesign = convertStringToFloat(row[23]);
        ppsNew->pps.injectCode = convertStringToFloat(row[24]);
        ppsNew->pps.injectCompile = convertStringToFloat(row[25]);
        ppsNew->pps.injectTest = convertStringToFloat(row[26]);


        ppsNew->pps.removePlanning = convertStringToFloat(row[27]);
        ppsNew->pps.removeDesign = convertStringToFloat(row[28]);
        ppsNew->pps.removeCode = convertStringToFloat(row[29]);
        ppsNew->pps.removeCompile = convertStringToFloat(row[30]);
        ppsNew->pps.removeTest = convertStringToFloat(row[31]);
        ppsNew->pps.removeAfterDevelopment = convertStringToFloat(row[32]);

        strcpy(ppsNew->pps.ppsType,row[33]);

        if(pps==NULL)
        {
            pps = ppsNew;
            sub = pps;
        }
        else
        {
            sub->next = ppsNew;
            ppsNew ->prev = sub;
            sub = sub->next;
        }
    }
    return pps;
}






int updatePPS(ProjectPlanSummary pps)
{
    string25 summaryLOCPerHour;
    string25 summaryPlanTime;
    string25 summaryActualTime;
    string25 summaryCPI;
    string25 summaryPercentReused;
    string25 summaryPercentNewReused;

    string25 programSizeBase;
    string25 programSizeDeleted;
    string25 programSizeModified;
    string25 programSizeAdded;
    string25 programSizeReused;
    string25 programSizeNewAndChanged;
    string25 programSizeTotalLOC;
    string25 programSizeNewReused;

    string25 trlPlanning;
    string25 trlDesign;
    string25 trlCode;
    string25 trlCompile;
    string25 trlTest;
    string25 trlPostmortem;

    string25 injectPlanning;
    string25 injectDesign;
    string25 injectCode;
    string25 injectCompile;
    string25 injectTest;


    string25 removePlanning;
    string25 removeDesign;
    string25 removeCode;
    string25 removeCompile;
    string25 removeTest;
    string25 removeAfterDevelopment;

    convertFloatToString(summaryLOCPerHour,pps.summaryLOCPerHour);
    convertFloatToString(summaryPlanTime,pps.summaryPlanTime);
    convertFloatToString(summaryActualTime,pps.summaryActualTime);
    convertFloatToString(summaryCPI,pps.summaryCPI);
    convertFloatToString(summaryPercentReused,pps.summaryPercentReused);
    convertFloatToString(summaryPercentNewReused,pps.summaryPercentNewReused);


    convertFloatToString(programSizeBase,pps.programSizeBase);
    convertFloatToString(programSizeDeleted,pps.programSizeDeleted);
    convertFloatToString(programSizeModified,pps.programSizeModified);
    convertFloatToString(programSizeAdded,pps.programSizeAdded);
    convertFloatToString(programSizeReused,pps.programSizeReused);
    convertFloatToString(programSizeNewAndChanged,pps.programSizeNewAndChanged);
    convertFloatToString(programSizeTotalLOC,pps.programSizeTotalLOC);
    convertFloatToString(programSizeNewReused,pps.programSizeNewReused);


    convertFloatToString(trlPlanning,pps.trlPlanning);
    convertFloatToString(trlDesign,pps.trlDesign);
    convertFloatToString(trlCode,pps.trlCode);
    convertFloatToString(trlCompile,pps.trlCompile);
    convertFloatToString(trlTest,pps.trlTest);
    convertFloatToString(trlPostmortem,pps.trlPostmortem);


    convertFloatToString(injectPlanning,pps.injectPlanning);
    convertFloatToString(injectDesign,pps.injectDesign);
    convertFloatToString(injectCode,pps.injectCode);
    convertFloatToString(injectCompile,pps.injectCompile);
    convertFloatToString(injectTest,pps.injectTest);


    convertFloatToString(removePlanning,pps.removePlanning);
    convertFloatToString(removeDesign,pps.removeDesign);
    convertFloatToString(removeCode,pps.removeCode);
    convertFloatToString(removeCompile,pps.removeCompile);
    convertFloatToString(removeTest,pps.removeTest);
    convertFloatToString(removeAfterDevelopment,pps.removeAfterDevelopment);

    int error = 0;
    string1000 script = "update pps set summaryLOCPerHour = '";
    strcat(script,summaryLOCPerHour);
    strcat(script,"' , summaryPlanTime = '");
    strcat(script,summaryPlanTime);
    strcat(script,"' , summaryActualTime = '");
    strcat(script,summaryActualTime);
    strcat(script,"' , summaryCPI = '");
    strcat(script,summaryCPI);
    strcat(script,"' , summaryPercentReused = '");
    strcat(script,summaryPercentReused);
    strcat(script,"' , summaryPercentNewReused = '");
    strcat(script,summaryPercentNewReused);

    strcat(script,"' , programSizeBase = '");
    strcat(script,programSizeBase);
    strcat(script,"' , programSizeDeleted = '");
    strcat(script,programSizeDeleted);
    strcat(script,"' , programSizeModified = '");
    strcat(script,programSizeModified);
    strcat(script,"' , programSizeAdded = '");
    strcat(script,programSizeAdded);
    strcat(script,"' , programSizeReused = '");
    strcat(script,programSizeReused);
    strcat(script,"' , programSizeNewAndChanged = '");
    strcat(script,programSizeNewAndChanged);
    strcat(script,"' , programSizeTotalLOC = '");
    strcat(script,programSizeTotalLOC);
    strcat(script,"' , programSizeNewReused = '");
    strcat(script,programSizeNewReused);

    strcat(script,"' , trlPlanning = '");
    strcat(script,trlPlanning);
    strcat(script,"' , trlDesign = '");
    strcat(script,trlDesign);
    strcat(script,"' , trlCode = '");
    strcat(script,trlCode);
    strcat(script,"' , trlCompile = '");
    strcat(script,trlCompile);
    strcat(script,"' , trlTest = '");
    strcat(script,trlTest);
    strcat(script,"' , trlPostmortem = '");
    strcat(script,trlPostmortem);

    strcat(script,"' , injectPlanning = '");
    strcat(script,injectPlanning);
    strcat(script,"' , injectDesign = '");
    strcat(script,injectDesign);
    strcat(script,"' , injectCode = '");
    strcat(script,injectCode);
    strcat(script,"' , injectCompile = '");
    strcat(script,injectCompile);
    strcat(script,"' , injectTest = '");
    strcat(script,injectTest);

    strcat(script,"' , removePlanning = '");
    strcat(script,removePlanning);
    strcat(script,"' , removeDesign = '");
    strcat(script,removeDesign);
    strcat(script,"' , removeCode = '");
    strcat(script,removeCode);
    strcat(script,"' , removeCompile = '");
    strcat(script,removeCompile);
    strcat(script,"' , removeTest = '");
    strcat(script,removeTest);
    strcat(script,"' , removeAfterDevelopment = '");
    strcat(script,removeAfterDevelopment);


    strcat(script,"' , ppsType = '");
    strcat(script,pps.ppsType);

    strcat(script,"'  where ppsID = '");
    strcat(script,pps.id);
    strcat(script,"'");

    error = mysql_query(conn, script); /*execute the script*/
    return error;
}






/*End Of MySQL Functions*/


#endif // BACKEND
